In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how Linux looks at threads. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The process of the Linux system is composed of threads, of course, the number of threads under the Linux process is not fixed, it can be one process or multiple processes.
The pstree command displays the relationship between processes (display a tree of processes) in a tree diagram. The ps command can display information about those processes that are currently running, but it is not clear enough about the relationship between them. In the Linux system, the system call fork can create the child process, and the child process can also be created through the child shell. The relationship between the processes in the Linux system is born a tree, and the root of the tree is the init process whose process PID is 1.
1 >. Install the pstree command line tool, package name: "psmisc"
[root@yinzhengjie bin] # yum-y install psmisc Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies-- > Running transaction check-- > Package psmisc.x86_64 0y install psmisc Loaded plugins 22.20-15.el7 will be installed-- > Finished Dependency Resolution Dependencies Resolved = Package Arch Version Repository Size = Installing: psmisc x86 / 64 22.20-15.el7 base 141k Transaction Summary = Install 1 Package Total download size: 141 k Installed size: 475 k Downloading packages: psmisc-22.20-15.el7.x86_64 .rpm | 141 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing: psmisc-22.20-15.el7.x86_64 1 Verifying: psmisc-22.20-15.el7.x86_64 1 Installed: psmisc. X86, 640, purl 22.20-15.el7 Complete! [root@yinzhengjie bin] # [root@yinzhengjie bin] # yum-y install psmisc
2 >. Introduction of related parameters
Usage: pstree [- a] [- c] [- h |-H PID] [- l] [- n] [- p] [- g] [- u] [- A |-G |-U] [PID | USER] pstree-V Display a tree of processes. -a,-- arguments displays the command and the full contents of its parameters-A,-- ascii the connection between the process trees with ASCII code characters to connect-c -- compact cancels merging of sibling processes of the same name (default merges sibling processes of the same name)-h,-highlight-all highlights the current process and its ancestor-H PID,-- highlight-pid=PID highlights this process and its ancestor-g -- show-pgids displays process group ID -G,-- vt100 uses VT100 lines to draw characters-l,-- long do not truncate long lines. -n,-- numeric-sort sorts the output with PID-N type,-- ns-sort=type sort by namespace type (ipc, mnt, net, pid, user, uts)-p,-- show-pids also lists the PID-s of each process. -- show-parents displays the parents of the selected process-S,-- ns-changes displays the namespace conversion-u,-- uid-changes also lists the account name of each process-U -- unicode connections between process trees are connected with utf8 characters Some terminals may have errors-V,-version displays version information-Z,-- security-context displays SELinux's security context PID starting with this PID The default value is 1 (init). USER only displays tree 3 > in the user's process. Case 1-showing the relationship between processes
[root@yinzhengjie bin] # pstree-apnh systemd,1-switched-root-system-deserialize 22 ├─ systemd-journal,730 ├─ systemd-udevd,758 ├─ lvmetad,761-f ├─ auditd,1006 │ └─ {auditd}, 1007 ├─ irqbalance,1040-foreground ├─ systemd-logind,1041 ├─ polkitd,1043-no-debug │ ├─ {polkitd}, 1048 │ ├─ {polkitd}, 1051 │ ├─ {polkitd} 1053 │ ├─ {polkitd}, 1054 │ └─ {polkitd}, 1055 ├─ dbus-daemon,1044-- system-- address=systemd:-- nofork-- nopidfile-- systemd-activation ├─ NetworkManager,1046-- no-daemon │ ├─ {NetworkManager}, 1072 │ └─ {NetworkManager}, 1074 ├─ crond,1047-n ├─ chronyd,1060 ├─ agetty,1065-noclear tty1 linux ├─ sshd,1400-D │ ├─ sshd 1985 │ │ └─ bash,1987 │ │ └─ pstree,1660-apnh │ └─ sshd,2017 │ └─ bash,2019 ├─ tuned,1401-Es / usr/sbin/tuned-l-P │ ├─ {tuned}, 1706 │ ├─ {tuned}, 1707 │ ├─ {tuned}, 1708 │ └─ {tuned}, 1779 gmetad,1402-d en20# {gmetad} 1403 │ ├─ {gmetad}, 1404 │ ├─ {gmetad}, 1405 │ ├─ {gmetad}, 1406 │ ├─ {gmetad}, 1407 │ ├─ {gmetad}, 1408 │ ├─ {gmetad}, 1409 │ └─ {gmetad}, 1410 ├─ httpd,1411-DFOREGROUND │ ├─ httpd,1757-DFOREGROUND │ ├─ httpd,1758-DFOREGROUND httpd,1759-DFOREGROUND 1760-DFOREGROUND │ └─ httpd,1761-DFOREGROUND ├─ rsyslogd,1414-n │ ├─ {rsyslogd}, 1421 │ └─ {rsyslogd}, 1427 ├─ zabbix_agentd,1418-c / etc/zabbix/zabbix_agentd.conf │ ├─ zabbix_agentd,1420 │ ├─ zabbix_agentd,1422 │ ├─ zabbix_agentd,1423 │ ├─ zabbix_agentd,1424 │ └─ zabbix_agentd,1425 ├─ gmond 1851 │ └─ {gmond}, 1855 └─ java,2484-Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE-cp/soft/zk/bin/../build/classes:/soft/zk/bin/../build/lib/*.jar:/soft/zk/bin/../lib/ ├─ {java}, 2487 ├─ {java}, 2488 ├─ {java}, 2489 ├─ {java}, 2490 ├─ {java}, 2491 ├─ {java}, 2492 ├─ {java} 2493 ├─ {java}, 2494 ├─ {java}, 2495 ├─ {java}, 2496 ├─ {java}, 2497 ├─ {java}, 2498 ├─ {java}, 2499 ├─ {java}, 2500 ├─ {java}, 2501 ├─ {java}, 2502 ├─ {java}, 2503 ├─ {java}, 2504 ├─ {java}, 2505 ├─ {java} 2506 ├─ {java}, 2507 ├─ {java}, 2508 ├─ {java}, 2509 ├─ {java}, 2510 ├─ {java}, 2511 ├─ {java}, 2512 ├─ {java}, 2513 ├─ {java}, 2514 ├─ {java}, 2515 ├─ {java}, 2516 ├─ {java}, 2517 ├─ {java}, 2518 ├─ {java} 2519 ├─ {java}, 2520 ├─ {java}, 2521 ├─ {java}, 2522 ├─ {java}, 2523 ├─ {java}, 2524 ├─ {java}, 2525 ├─ {java}, 2526 ├─ {java}, 2527 ├─ {java}, 2528 ├─ {java}, 2529 ├─ {java}, 2530 ├─ {java}, 2531 ├─ {java} 2532 ├─ {java}, 2534 ├─ {java}, 2535 ├─ {java}, 2536 ├─ {java}, 2537 ├─ {java}, 2538 ├─ {java}, 2539 ├─ {java}, 2540 ├─ {java}, 2541 ├─ {java}, 2542 ├─ {java}, 2543 ├─ {java}, 2544 ├─ {java}, 2545 ├─ {java} 2546 ├─ {java}, 2547 ├─ {java}, 2548 └─ {java}, 2549 [root@yinzhengjie bin] # [root@yinzhengjie bin] # pstree-apnh
4 >. Case 2-shows the process in a tree view, as well as the process PID
[root@yinzhengjie bin] # pstree-p systemd (1) ─┬─ NetworkManager (1046) ─┬─ {NetworkManager} (1072) │ └─ {NetworkManager} (1074) ├─ agetty (1065) ├─ auditd (1006) ─── {auditd} (1007) ├─ chronyd (1060) ├─ crond (1047) ├ ─ dbus-daemon (1044) ├─ gmetad (1402) ─┬─ {gmetad} (1403) │ ├─ {gmetad} (1404) │ ├─ {gmetad} (1405) │ ├─ (1406) │ ├─ {gmetad} (1407) │ ├─ {gmetad} (1408) │ ├─ {gmetad} (1409) │ └─ {gmetad} (1410) ├─ gmond (1851) ─── {gmond} (1855) ├─ httpd (1411) ─┬─ httpd (1757) │ ├─ httpd 1758) │ ├─ httpd (1759) │ ├─ httpd (1760) │ └─ httpd (1761) ├─ irqbalance (1040) ├─ java (2484) ─┬─ {java} (2487) │ ├─ {java} (2488) │ ├─ {java} (2489) │ ├─ {java} (2490) │ ├─ {java} (2491) │ ├─ {java} (2492) │ ├─ {java} (2493) │ ├─ ( 2494) │ ├─ {java} (2495) │ ├─ {java} (2496) │ ├─ {java} (2497) │ ├─ {java} (2498) │ ├─ {java} (2499) │ ├─ {java} (2500) │ ├─ {java} (2501) │ ├─ {java} (2502) │ ├─ {java} (2503) │ ├─ (2504) │ ├─ {java} (2505) │ ├─ {java} (2506) │ ├─ {java} (2507) │ ├─ {java} (2508) │ ├─ {java} (2509) │ ├─ (2510) │ ├─ {java} (2511) │ ├─ {java} (2512) │ ├─ {java} (2513) │ ├─ {java} (2514) │ ├─ {java} (2515) │ ├─ (2516) │ ├─ { Java} (2517) │ ├─ {java} (2518) │ ├─ {java} (2519) │ ├─ {java} (2520) │ ├─ {java} (2521) │ ├─ {java} (2522) │ ├─ {java} (2523) │ ├─ {java} (2524) │ ├─ {java} (2525) │ ├─ {java} (2526) │ ├─ (2527) │ ├─ {java} (2528) │ ├─ {java} (2529) │ ├─ {java} (2530) │ ├─ {java} (2531) │ ├─ {java} (2532) │ ├─ {java} (2534) │ ├─ ( 2535) │ ├─ {java} (2536) │ ├─ {java} (2537) │ ├─ {java} (2538) │ ├─ {java} (2539) │ ├─ {java} (2540) │ ├─ {java} (2541) │ ├─ {java} (2542) │ ├─ {java} (2543) │ ├─ {java} (2544) │ ├─ (2545) │ ├─ {java} (2546) │ ├─ {java} (2547) │ ├─ {java} (2548) │ └─ {java} (2549) ├─ lvmetad (2549) ├─ polkitd (1043) ─┬─ {polkitd} (1048) │ ├─ {polkitd} (1051) │ ├─ {polkitd} (1053) │ ├─ {polkitd} (1054) │ └─ {polkitd} (1055) ├─ rsyslogd (1414) ─┬─ {rsyslogd} (1421) │ └─ {rsyslogd} (1427) ├─ sshd (1400) ─┬─ Sshd (1985) ─── bash (1987) ─── pstree (2403) │ └─ sshd (2017) ─── bash (2019) ├─ systemd-journal (730) ├─ systemd-logind (1041) ├─ systemd-udevd (758) ├─ tuned (1401) ─┬─ {tuned} (1706) │ ├─ {tuned} (1707) │ ├─ {tuned} (1708) │ └─ {tuned} (1779) └─ zabbix_agentd (1418) ─┬─ zabbix_agentd (1420) ├─ zabbix_agentd (1422) ├─ Zabbix_agentd (1423) ├─ zabbix_agentd (1424) └─ zabbix_agentd (1425) [root@yinzhengjie bin] # [root@yinzhengjie bin] # pstree-p
5 >. Case 3: show the command and its complete parameters *
[root@yinzhengjie bin] # pstree-a systemd--switched-root-system-deserialize 22 ├─ NetworkManager-no-daemon │ └─ 2 * [{NetworkManager}] ├─ agetty-noclear tty1 linux ├─ auditd │ └─ {auditd} ├─ chronyd ├─ crond-n ├─ dbus-daemon-system-address=systemd:-nofork-nopidfile-systemd-activation ├─ gmetad d 1 │ └─ 8* [ {gmetad}] ├─ gmond │ └─ {gmond} ├─ httpd-DFOREGROUND │ ├─ httpd-DFOREGROUND │ └─ httpd-DFOREGROUND ├─ irqbalance-foreground ├─ java-Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO CONSOLE-cp/soft/zk/bin/../build/classes:/soft/zk/bin/../build/lib/*.jar:/soft/zk/bin/../lib/ │ └─ 62 * [{java}] ├─ lvmetad-f ├─ polkitd-- no-debug │ └─ 5 * [{polkitd}] ├─ rsyslogd-n │ └─ 2* [{rsyslogd}] ├─ sshd-D │ ├─ sshd │ │ └─ bash │ │ └─ pstree-a │ └─ sshd │ └─ bash ├─ systemd-journal ├─ systemd-logind ├─ systemd-udevd ├─ tuned-Es / usr/sbin/tuned-l-P │ └─ 4* [{tuned}] └─ zabbix_agentd-c / etc/zabbix/zabbix_agentd.conf ├─ zabbix_agentd ├─ zabbix_agentd ├─ zabbix_agentd ├─ zabbix_agentd └─ zabbix_agentd [root@yinzhengjie bin] # [root@yinzhengjie bin] # pstree-a
6 >. Case 4-cancel the merge, merge sibling processes with the same name by default,-c cancel the merge and display separately
[root@yinzhengjie bin] # pstree-c systemd ─┬─ NetworkManager ─┬─ {NetworkManager} │ └─ {NetworkManager} ├─ agetty ├─ auditd ─── {auditd} ├─ chronyd ├─ crond ├─ dbus-daemon ├─ gmetad ─┬─ {gmetad} │ ├─ {gmetad} │ ├─ {gmetad} │ ├─ {gmetad} │ └─ {gmetad} ├─ gmond ─── {gmond} ├─ httpd ─┬─ httpd │ ├─ Httpd │ ├─ httpd │ ├─ httpd │ └─ httpd irqbalance ├─ java ─┬─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java} │ ├─ {java } │ ├─ {java} │ ├─ {java} │ └─ {java} ├─ lvmetad ├─ polkitd ─┬─ {polkitd} │ ├─ {polkitd} │ ├ ─ {polkitd} │ ├─ {polkitd} │ └─ {polkitd} ├─ rsyslogd ─┬─ {rsyslogd} │ └─ {rsyslogd} ├─ sshd ─┬─ sshd ─── bash ─── pstree │ └─ sshd ─── bash ├─ systemd-journal ├─ systemd-logind ├─ systemd-udevd ├─ tuned ─┬─ {tuned} │ ├─ {tuned} │ ├─ {tuned} │ └─ {tuned} └─ zabbix_agentd ─┬─ zabbix_agentd ├─ zabbix_agentd ├─ zabbix_agentd ├─ zabbix_agentd └─ zabbix_agentd [root@yinzhengjie bin] # [root@yinzhengjie bin] # pstree-c
7 >. Case 5-query the number of threads opened by the zookeeper process
[root@yinzhengjie bin] # jps 2484 QuorumPeerMain 5127 Jps [root@yinzhengjie bin] # [root@yinzhengjie bin] # [root@yinzhengjie bin] # pstree-p `jps | grep QuorumPeerMain | awk'{print $1}'`| wc-l 62 [root@yinzhengjie bin] # [root@yinzhengjie bin] # [root@yinzhengjie bin] # pstree-p 2484 | wc-l 62 [root@yinzhengjie bin] # Summary:
The parent-child relationship of the process can be seen clearly through pstree, but the process status check still requires commands such as ps, top, and so on. The pstree command is used to view the relationship between the process trees, that is, which process is the parent process and which is the child process, you can clearly see who created whom.
Recommended blog for learning: http://www.runoob.com/linux/linux-command-manual.html
two。 Use the top command to view
1 >. Use the pstree command to view the number of threads open by the "ResourceManager" process
[root@yinzhengjie ~] # jps 6178 Jps 10339 ResourceManager 10309 JobTracker 9462 NameNode 9464 Bootstrap 9466 DFSZKFailoverController 11052 HistoryServer 11054 HistoryServer 10367 JobHistoryServer [root@yinzhengjie] # [root@yinzhengjie] # [root@yinzhengjie] # pstree-p 10339 | wc-l248 [root@yinzhengjie] # 2 >. Use the top command to view the number of processes opened by "ResourceManager"
[root@yinzhengjie] # top-H-p 10339 top-01:38:45 up 7 days, 1:33, 3 users, load average: 0.02,0.06,0.05 Threads: 247 total, 0 running, 247 sleeping, 0 stopped, 0 zombie% Cpu (s): 0.1 us, 0.0 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 18328176 total, 11610648 free, 5253524 used 1464004 buff/cache KiB Swap: 9306108 total, 9306108 free, 0 used. 12658008 avail Mem PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND 10791 yarn 200 3131380 622256 23808 S 0.33.4 015.83 java 10339 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:00.25 java 10608 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:03.12 java 10609 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.65 java 10610 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.65 java 10611 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.69 java 10612 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.66 java 10613 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.70 java 10614 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.69 java 10615 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01 . 67 java 10616 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.68 java 10617 Yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.68 java 10618 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.67 java 10619 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.70 java 10620 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.68 java 10621 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.66 java 10622 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.67 java 10623 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:01.69 java 10624 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:00.00 java 10625 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:00.00 java 10626 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:00.00 java 10627 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:00 . 00 java 10628 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:15.73 java 10645 Yarn 20 0 3131380 622256 23808 S 0.0 3.4 1:59.54 java 10651 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:00.06 java 10652 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:00.04 java 10656 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:00.00 java 10657 yarn 20 0 3131380 622256 23808 S 0.0 3.4 0:00.00 java 10658 yarn 20 0 3131380 622256 23808 S 0.03.4 08.24 java [root@yinzhengjie ~] # [root@yinzhengjie ~] # top-H-p 10339
three。 Go directly to the status directory of "/ proc" corresponding to PID.
Because in the Linux operating system, running programs will store the status information of run-time files in the / proc directory, so we can find the corresponding process ID in this directory to see the number of threads opened by the process. Of course, there are other details stored in this directory.
[root@yinzhengjie] # cat / proc/10339/status Name: java Umask: 0022 State: s (sleeping) Tgid: 10339 Ngid: 0 Pid: 10339 PPid: 8410 TracerPid: 0 Uid: 988 988 988 Gid: 985 985 985 FDSize: 512 Groups: 985 994 VmPeak: 3131384 kB VmSize: 3131380 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 622300 kB VmRSS : 622256 kB RssAnon: 598448 kB RssFile: 23808 kB RssShmem: 0 kB VmData: 2962116 kB VmStk: 144 kB VmExe: 4 kB VmLib: 17152 kB VmPTE: 1808 kB VmSwap: 0 kB Threads: 248 SigQ: 0/71498 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: 2000000181005ccf CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000001fffffffff CapAmb: 0000000000000000 Seccomp: 0 Cpus_allowed: fffff Cpus_allowed_list: 0-19 Mems_allowed: 00000000recorder 00000000recorder 00000000recorder 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
4. * go directly to the task directory of "/ proc" corresponding to PID to check *
[root@yinzhengjie ~] # jps 8704 Jps 10339 ResourceManager 10309 JobTracker 9462 NameNode 9464 Bootstrap 9466 DFSZKFailoverController 11052 HistoryServer 11054 HistoryServer 10367 JobHistoryServer [root@yinzhengjie] # [root@yinzhengjie] # [root@yinzhengjie] # pstree-p 10339 | wc-l248 [root@yinzhengjie ~] # [root@yinzhengjie ~] # [root@yinzhengjie ~] # ll / proc/10339/task/ | wc-l248 [root@yinzhengjie ~] # [root@yinzhengjie ~] # Thank you for reading! This is the end of this article on "how to check threads in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.