First, Pstree command
1. Introduction to Commands
Displays the process in a tree view, showing only the name of the process, and the same process is displayed in the merge.
2. Common options and examples
2.1. Displays the process in a tree view, and also shows the process PID:
[[Email protected] ~]# pstree -pinit (1) ─┬─auditd (937) ───{AUDITD} (938) ├─crond (1322) ├─dbus-daemon (1041) ├─master (1312) ─┬─pickup (1485) │ └─qmgr ( 1326) ├─mingetty (1337) ├─mingetty (1339) ├─mingetty (1341) ├─mingetty (1343) ├─mingetty (1348) ├─mingetty (1350) ├─nginx (1078) ───nginx (        ├─RPC.STATD) (997) &nBSP; ├─RSYSLOGD (957) ─┬─{rsyslogd} (958) │             ├─{RSYSLOGD} (960) │   └─{RSYSLOGD} (961) ├─sshd (1101) ───sshd (1351) ───bash ( 1353) ───pstree (1753) └─udevd (368) ─┬─udevd (1346)  └─UDEVD (1347)
2.2, a tree view of the specified running PID process and descendants of the process, if you have the-p parameter to display the PID of each process:
[Email protected] ~]# pstree-p 368udevd (368) ─┬─udevd (1346) └─UDEVD (1347)
Second, PS command
1. Introduction to Commands
The PS command in Linux is the abbreviation for process status. The PS command is used to list those processes that are currently running on the system. The PS command lists the current snapshots of those processes, the ones that were executed at the time of the PS command, and if you wanted to display process information dynamically, you could use the top and Htop commands.
2. Common options
A Show All Processes
-E Show All processes
F show the relationship between programs
U specify all processes for the user
-c< commands > lists the status of the specified command
X is usually used in conjunction with the A parameter to list more complete information.
- o Customizing the information to display
-p<pid> show the process of the specified PID
3. Use Example
3.1, out of all the current memory of the program:
[[email protected] ~]# ps aux //or using PS -ef the results are almost user pid %cpu %mem VSZ RSS TTY STAT START time commandroot 1 0.0 0.1 2900 1412 ? Ss jul15 0:01 /sbin/initroot 2 0.0 0.0 0 0 ? s jul15 0:00 [ kthreadd]root 3 0.0 0.0 0 &nbSp; 0 ? s jul15 0:00 [migration/0]root 4 0.0 0.0 0 0 ? s jul15 0:00 [ksoftirqd /0]root 5 0.0 0.0 0 0 ? s Jul15 0:00 [stopper/0]root 6 0.0 0.0 0 0 ? S Jul15 0:00 [watchdog/0] ...................................
Description
User: The process belongs to the user account
PID: The number of the process
%cpu: Percentage of CPU resources that the process uses
%MEM: Percentage of physical memory occupied by this process
VSZ: The amount of virtual memory that the process uses (Kbytes)
RSS: The amount of fixed memory that the process occupies (Kbytes)
TTY: The process is operating on that terminal, if it is not related to the terminal, then display?, in addition, TTY1-TTY6 is the machine above the login program, if it is pts/0 and so on, it is represented by the network connected to the host computer program.
STAT: The current state of the program, the main state has
R: The program is currently in operation or can be operated
S: The program is currently sleeping (can be said to be idle) but can be awakened by certain signals (signal).
T: The program is currently detecting or stopping
Z: The program should have been terminated, but the parent program could not properly terminate him, causing the state of the zombie (Xinjiang Corpse) program
Start: The time that the process was triggered to start
Time: The process actually uses the CPU to run
Command: The actual instruction of the program
3.2. Display the specified user process
Use the "-u" option followed by the user name to filter the processes of the owning user, and multiple user names can be separated by commas.
[[email protected] ~]# ps-f-u nobodyuid PID PPID C stime TTY time cmdnobody 1815 1814 0 00:26? 00:00:00 Nginx:worker Process
3.3. Sort the process by using CPU or memory
When we want to show a process that consumes the highest CPU or memory resources in a system, it is common to think of the top command to dynamically display a high-to-low sort by typing p or m, while the PS command can specify multiple fields with '--sort ' and separate them with commas. In addition, the field can be preceded by a '-' or ' + ' prefix to indicate the descending and ascending sort accordingly:
[[email protected] ~]# ps aux --sort=-pcpu | head -5user pid %cpu %mem vsz rss tty STAT START TIME COMMANDroot 1 0.0 0.1 2900 1412 ? ss jul15 0:01 / sbin/initroot 2 0.0 0.0 0 0 ? S Jul15 0:00 [kthreadd]root 3 0.0 0.0 0 0 ? s jul15 0:00 [migration/ 0]root 4 0.0 0.0 0 0 ? s &NBSP;&NBSP;&NBSP;&NBSP;JUL15&NBSP;&NBSP;&NBSP;0:00&NBSP;[KSOFTIRQD/0]
3.3. Change the displayed columns
The following command displays only the PID, user name, CPU, memory, and command columns:
[[email protected] ~]# ps-e-o pid,uname,pcpu,pmem,comm pid USER%cpu%MEM COMMAND 1 root 0.0 0.1 init 2 root 0.0 0.0 kthreadd 3 root 0.0 0.0 migration/0 4 root 0.0 0.0 ksoftirqd/0 5 root 0.0 0.0 stopper/0 ....... ........................
3.4. Show when the process is running
The run time refers to the time that the process has been running. The Run Time column does not appear by default and needs to be brought in using the-o option.
[[email protected] ~]# ps-e-o pid,comm,etime pid COMMAND ELAPSED 1 init 08:13:49 2 kthr Eadd 08:13:49 3 migration/0 08:13:49 4 ksoftirqd/0 08:13:49 5 stopper/0 08:13:49 .................................
3.5. Show process by name or process ID
Search for a process by adding a name or command after the "-C" option:
[[email protected] ~]# ps-c nginx PID TTY time CMD 1814? 00:00:00 nginx 1815? 00:00:00 Nginx
To display the process through the process ID, use the "-P" option, and you can also specify multiple process IDs by separating them with commas.
[[email protected] ~]# ps-f-P 28,23,45uid PID PPID C stime TTY time cmdroot 2 0 Jul15? 00:00:00 [khubd]root 2 0 Jul15? 00:00:00 [khungtaskd]root 2 0 Jul15? 00:00:00 [DEFERWQ]
"-C" must provide an exact process name, and it cannot be found by partial names or wildcard characters. For more flexibility in searching the list of processes, the grep command is typically used.
[[email protected] ~]# ps aux |grep nginxroot 1814 0.0 0.0 5380 636 ? Ss 00:26 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confnobody 1815 0.0 0.0 5564 988 ? s 00:26 0:00 nginx: worker process root 1879 0.0 0.0 5980 740 pts/0 s+ 00:56 0:00 grep nginx
3.6. Convert PS to class is the real-time process viewer of the top command
[Email protected] ~]# watch-n 1 ' ps-e-o pid,uname,cmd,pmem,pcpu--sort=-pmem,-pcpu | Head-5 '
Every 10.0s: ps -e -o pid,uname,cmd,pmem,pcpu --so... thu jul 16 01:02:26 2015 PID USER CMD %mem %cpu 1 root /sbin/ init 0.1 0.0 2 root [kthreadd] 0.0 0.0 3 root [migration/0] 0.0 0.0 4 root [ksoftirqd/0] 0.0 0.0
The output will refresh every second, but this is actually different from top. You will find that the output of the Top/htop command is refreshed more frequently than the PS command above. This is because the top output is a sorted value that combines the CPU usage values and memory usage values. But the PS command above is a simpler sort of behavior that gets one column at a time (like math at school), so it doesn't update as fast as top.
Reference:
http://linux.cn/thread/12046/1/1/
This article is from the "Bread" blog, make sure to keep this source http://cuchadanfan.blog.51cto.com/9940284/1675446
Linux System network commands (iv)