in DevOps

Count number of thread in a linux process

There are multiple way for finding out the number of thread spawned by a process. Simplest or one of the way if to find from the /proc status of the process.

The proc pseudo filesystem, which resides in /proc directory, is the easiest way to see the thread count of any active process. The /proc directory exports in the form of readable text files a wealth of information related to existing processes and system hardware such as CPU, interrupts, memory, disk, etc.

$ cat /proc/<pid>/status

The above command will show detailed information about the process with <pid>, which includes process state (e.g., sleeping, running), parent PID, UID, GID, the number of file descriptors used, and the number of context switches. The output also indicates the total number of threads created in a process as follows.


[email protected]:~# cat /proc/28342/status | grep Thread
Threads: 1

Other methods:

ps -T -p <pid of the process>