You can run this command under Linux (tested with RHEL 3.0) to see the processes with the most threads…
find /proc/*/status -exec gawk '/^Name:/ { n=$2}; /^Threads:/ { t=$2}; END{ printf("%-30s %5d\n", n, t);}' {} \; | sort --key=2 -g -r | head -10
This is especially useful on systems (like VPS hosting accounts) where you might have limits on the total number of threads.
Addendum (12/1/2006 1:48p CST):
Based on feedback, here are a few other tips related to this…
- You can modify the script slightly to also show the process id using this modified version…
find /proc/*/status -exec gawk '/^Pid:/ { p=$2}; /^Name:/ { n=$2}; /^Threads:/ { t=$2}; END{ printf("%6d %-30s %5d\n", p, n, t);}' {} \; | sort -k3 -g -r | head -10 - You can create a
topthreadsalias to this long command allowing to you execute it just by typingtopthreadsby first executing…alias topthreads="find /proc/*/status -exec gawk '/^Pid:/ { p=\$2}; /^Name:/ { n=\$2}; /^Threads:/ { t=\$2}; END{ printf(\"%6d %-30s %5d\n\", p, n, t);}' {} \; | sort -k3 -g -r | head -10"