Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've used 'top', but I need a tool that can give me an arbitrary-time history of threads that have executed on my system (CentOS 5.4)?


migration rejected from Feb 13 '15 at 13:58

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by random Feb 13 '15 at 13:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking product, service, or learning material recommendations are off-topic because they become outdated quickly and attract opinion-based answers. Instead, describe your situation and the specific problem you're trying to solve. Share your research. Here are a few suggestions on how to properly ask this type of question." – random
If this question can be reworded to fit the rules in the help center, please edit the question.

10 Answers 10

ps -eLf will give you a list of all the threads and processes currently running on the system.

However you ask for a list of all threads that HAVE executed on the system, presumably since some arbitrary point in the past - are you sure that is what you mean? You could run ps as a cron job and poll the system every X minutes, but you would miss threads that were born and died between jobs. You would also have a huge amount of data to deal with.

you also use watch ps command in order to constantly see the current threads, not history related, still quite useful – Tim Jun 13 '14 at 13:22
Just a note to those of you who think you know the "eLf" idiom - the capital L matters. You will not get all threads if you use lower case l. – Sridhar-Sarnobat Jul 22 '14 at 5:09
@Tim watch doesn't monitor continuously, but polls repeatedly; on my system the interval defaults to 2s. – boycy Sep 17 '14 at 11:51
@boycy you can adjust the interval to the duration as you like say 100ms and getting the feeling of continuity :) – Tim Sep 17 '14 at 19:44

run top, then hit 'H' to toggle thread listing


use the ps command.

From the man page, there are a few thread options:


-H Show threads as if they were processes

-L Show threads, possibly with LWP and NLWP columns

-T Show threads, possibly with SPID column

-m Show threads after processes


This command is useful in shell scripts or cron jobs for easy parsing, because it will only print a number. You can easily check if sum is greater than a threshold for your monitoring.

grep -s '^Threads' /proc/[0-9]*/status | awk '{ sum += $2; } END { print sum; }'

for me, prints:

This is useful on embedded systems, which have a stripped down version of top, which is missing the above features. – Trevor Aug 20 '14 at 14:16

I like htop. It's like top, but colour coded and with more features.

lsof is good if you want something more advanced. Here's an excellent lsof tutorial.

When using htop, press t to get a nested tree of threads. – ltn100 Dec 17 '14 at 14:41
First H to show threads, then t to toggle "tree view" on. – Dimitar Apr 9 '15 at 9:16

I am not aware of a logging solution in a single application. However, working with the more general logging / monitoring framework Zabbix I created the following definition to collect data on threads used by the application I wanted to monitor:

UserParameter=myapp.threads,ps --no-headers -L -p$(pgrep -x myapp)|wc -l

This one-line entry in the config makes Zabbix report, under the token 'myapp.threads' the number of threads seen each time the snippet is run. This picks up the process id via a first call to pgrep, then lists all threads using ps -L and counts them via wc -l.

Not the most elegant solution but it got the job done in a few minutes. Now, with Zabbix databasing and reporting, I can look at this through time. Of course, you probably wouldn't want to install Zabbix just for this.


I think Linux has process auditing support. You might be able to get that set up to log every thread-creation. I don't know how to do this; I've never wanted to add overhead to kernel functions that are supposed to be fast. :/


lsof is a great utility to list open files and threads


See sar, part of the sysstat package by Sebastien Godard.

The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. [...] The collected data can also be saved in the file specified by the -o filename flag, in addition to being displayed onto the screen. [...] By default all the data available from the kernel are saved in the data file.


use sar -q, it will give you the number of tasks in the task list under the column plist-sz.