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.
Asked
Active
Viewed 2,074 times
0
-
Asked and answered *ad nauseam*. You are expected to make an effort. Please show your code and state where you are having trouble. Also see [Why is the “how to move the turtle in logo” question closed?](https://meta.stackexchange.com/a/158334) and [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – jww Jun 17 '19 at 08:53
1 Answers
1
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.

Harijith R
- 329
- 2
- 8