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

前端 未结 17 917
暖寄归人
暖寄归人 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:37

    Newer JDK distributions ship with JConsole and VisualVM. Both are fantastic tools for getting the dirty details from a running Java process. If you have to do this programmatically, investigate JMX.

    0 讨论(0)
  • 2020-12-02 04:37

    VisualVM can show clear states of threads of a given JVM process

    0 讨论(0)
  • 2020-12-02 04:37

    If you want the number of threads per user in a linux system then you should use:

    ps -eLf | grep <USER> | awk '{ num += $6 } END { print num }'
    

    where as <USER> use the desired user name.

    0 讨论(0)
  • 2020-12-02 04:39

    My answer is more gui, but still within terminal. Htop may be used with a bit of setup.

    1. Start htop.
    2. Enter setup menu by pressing F2.
    3. From leftmost column choose "Columns"
    4. From rightmost column choose the column to be added to main monitoring output, "NLWP" is what you are looking for.
    5. Press F10.
    0 讨论(0)
  • 2020-12-02 04:41

    If you use:

    ps uH p <PID_OF_U_PROCESS> | wc -l
    

    You have to subtract 1 to the result, as one of the lines "wc" is counting is the headers of the "ps" command.

    0 讨论(0)
  • 2020-12-02 04:44

    Each thread in a process creates a directory under /proc/<pid>/task. Count the number of directories, and you have the number of threads.

    0 讨论(0)
提交回复
热议问题