How to get (from terminal) total number of threads (per process and total for all processes)
I tried googling it, but I can't find it. I am looking for:
number of threads in process X
total number of threads running currently
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 }'
For finding the number of threads running a single process you can look at /proc/<pid>/status
. It should list the number of threads as one of the fields.