Introduction: In the Java language, the thread is widely used, in most cases, people do not care about how many threads are created in the Java application, how to see how many threads the process actually started. This article gives a number of methods for the top command
TOP-HP PID
For example, the current PID is 1212, you can view the number of threads of the process, the program output is:
In the output information, the threads is clearly shown to be 14. PS Directive
PS HuH P pid| Wc-l
Here the PID is 1212, the output information of the current instruction is as follows:
14
The directive outputs the number of threads for the current process directly.
Another instruction is:
PS-T-P PID
If the current PID is 1212, all thread information is output:
All threads are listed here, unfortunately it takes a number of them. process-based status file
Cat/proc/{pid}/status
Here the PID is 1212, you can see the following information:
Threads:15
It is strange that the number of threads that are based on the proc status file is more than 1 threads more than the threads that were queried by the previous instruction.
This status file holds all relevant information about the current process:
(python36env)
[root@ay131203102210033c39z pdf-reader]# cat/proc/1212/status Name:java umask:0022 state:s (sleeping) tgid:1212
ngid:0 pid:1212 ppid:970 tracerpid:0 uid:0 0 0 0 gid:0 0 0 0 fdsize:64 groups:vmpeak:2094976 kb vmsize:2055272 KB vmlck:0 KB vmpin:0 kb vmhwm:67752 KB VmR ss:67752 KB rssanon:56928 KB rssfile:10824 KB rssshmem:0 KB vmdata:1890492 KB V mstk:132 KB vmexe:4 KB vmlib:17364 KB vmpte:320 KB vmswap:0 KB threads:14 sigq : 0/7282 sigpnd:0000000000000000 shdpnd:0000000000000000 sigblk:0000000000000000 sigign:0000000000000000 sigcgt:200
0000181005CCF capinh:0000000000000000 capprm:0000001fffffffff capeff:0000001fffffffff capbnd:0000001fffffffff capamb:0000000000000000 seccomp:0 cpus_allowed:1 cpus_allowed_list:0 mems_allowed:00000000,00000000,0 0000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000 000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000 , 00000001 mems_allowed_list:0 voluntary_ctxt_switches:84 nonvoluntary_ctxt_switches:4
The information is very rich ... htop Execution
Htop provides an enhanced version of the top directive, which allows you to directly see the number of threads on the interface by directly setting show custom thread names and tree View f2–>setup–> Display options–> Selection Out.
The above picture is the Htop setting interface.
Unfortunately, from the author's computer, see Htop still a little problem, the effect does not come out, this is not in the map. Summary
Provides a lot of ways, you can choose one on the basis of need.