System Info – How to Get Total Number of Threads via Terminal

system-info

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

Best Answer

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 }'
Related Question