How can I monitor the thread count of a process on linux?

前端 未结 17 1122
暖寄归人
暖寄归人 2020-12-02 03:53

I would like to monitor the number of threads used by a specific process on Linux. Is there an easy way to get this information without impacting the performance of the proc

17条回答
  •  隐瞒了意图╮
    2020-12-02 04:50

    To get the number of threads for a given pid:

    $ ps -o nlwp 
    

    Where nlwp stands for Number of Light Weight Processes (threads). Thus ps aliases nlwp to thcount, which means that

    $ ps -o thcount 
    

    does also work.

    If you want to monitor the thread count, simply use watch:

    $ watch ps -o thcount 
    

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

    $ ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }'
    

提交回复
热议问题