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)?

link|improve this question
5  
This is a job for.. Super User! – mmyers Dec 8 '09 at 17:47
4  
Sometimes you need to monitor apps you wrote or tools you work with. Let's not push all non-source code questions to SU. – Dirk Eddelbuettel Dec 8 '09 at 17:59
feedback

migrated from stackoverflow.com Dec 8 '09 at 20:26

This question came from our site for professional and enthusiast programmers.

9 Answers

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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

use the ps command.

link|improve this answer
feedback

ps ax | grep Apache

just replace Apache with the process you're looking for

link|improve this answer
ps -A | grep Apache works too! BTW, I never could figure out the difference between those two. – Dan Dec 8 '09 at 19:40
1  
he asked about threads, not processes – frunsi Dec 8 '09 at 19:55
1  
Correct me if I'm wrong, but doesn't Linux implement threads as processes? – BigBeagle Dec 8 '09 at 20:15
2  
No, it does not. – phresus Dec 8 '09 at 20:42
feedback

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. :/

link|improve this answer
feedback

lsof is a great utility to list open files and threads

link|improve this answer
feedback

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

link|improve this answer
feedback

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.

link|improve this answer
feedback

See sar(1) by Sebastien Godard.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown