Pages

Friday, April 19, 2013

Total Number Of Threads In a Linux Process


For a single-threaded process, you will find all the information about the state of the process under /proc/pid itself. For a multi-threaded process, the /proc/pid will have a sub directory called task. This directory contains contains one sub directory per thread, including the main thread: /proc/pid/task/tid1, /proc/pid/task/tid2, etc. The main thread has the thread ID same as the process ID.

The easiest way to find out if a given process is multi threaded or not is to examine the /proc/pid/task directory. If it contains many sub directories, its a multi-threaded process. Otherwise, it could be a single threaded one.

The Number of Threads that processes have can be given using
cat /proc/<PID>/status

Happy Learning :-)