Abhishek Paharva
Abhishek Paharva

Reputation: 5

How to find %RAM and %CPU consumption of individual thread of running process in Linux?

I creating an application for monitoring the thread of the running process. I want to find out no of threading it running and CPU and RAM consumption of individual thread.

Upvotes: 0

Views: 2827

Answers (1)

Harijith R
Harijith R

Reputation: 349

To get the number of threads for a given pid:

$ ps -o nlwp <pid>

Where nlwp stands for Number of Light Weight Processes (threads). Thus ps aliases nlwp to thcount, which means that

$ ps -o thcount <pid>

does also work.

Percent of cpu usage per thread you can get with ps command:

 ps -emo %cpu,pid,user,args

The way it is calculated is described in ps manpage:

Currently, it is the CPU time used divided by the time the process has been running (cputime/realtime ratio), expressed as a percentage.

Memory is not allocated to threads, and often shared across threads. This makes it generally impossible to find the memory usage per thread.

Upvotes: 1

Related Questions