I tried googling it, but I can't find it. I am looking for:

  1. number of threads in process X

  2. total number of threads running currently

link|improve this question

75% accept rate
feedback

2 Answers

up vote 2 down vote accepted

To get the number of threads for a given pid:

ps -o nlwp <pid>

To the get the sum of all threads running in the system:

ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }'
link|improve this answer
feedback

I'm basing this answer around ps axms. ps is a great tool for listing what's running.

If you want to filter that by a process, you could try something like this:

echo $(( `ps axms | grep firefox | wc -l`  - 1))

We subtract 1 because grep will show in that list.

For all threads in general this should work:

echo $(( `ps axms | wc -l`  - 1))

We subtract one this time because there is a header row.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.