Tuesday, June 12, 2012

List of thread Ids of a process in Linux using Proc


we have seen how to identify number of threads associated with a process in Linux. Read article Thread count in a linux process. Lets see the another tip to achieve the same task.

Using proc pseudo file system, one can get lot of useful information about a process and its thread. Each file in the proc file system has specific information about a process. Read about proc file system.


1.Idenfity process Id 

prompt # ps -eaf | grep rsyslog
root     31970     1  0 Jun11 ?        00:00:18 /sbin/rsyslogd -f /etc/rsyslog.conf
prompt #


Lets choose rsyslogd process

2. run 'ls -l /proc/31970/task' following command


prompt # ls -l /proc/31970/task
total 0
dr-xr-xr-x. 5 root root 0 Jun 12 14:53 22740
dr-xr-xr-x. 5 root root 0 Jun 12 14:53 31970
dr-xr-xr-x. 5 root root 0 Jun 12 14:53 31973
dr-xr-xr-x. 5 root root 0 Jun 12 14:53 31974
dr-xr-xr-x. 5 root root 0 Jun 12 14:53 31975


There are 5 threads associated with process id 31970. Each file name shows the thread ID.

3. verify the number of threads 


prompt # cat /proc/31970/status | grep -i threads
Threads:        5


#2 and #3 details are matching.

Hope you like it. please share this tip.


Pin It
Related Posts Plugin for WordPress, Blogger...