The ps Command provides a one-time view of the process results. The results provided by the ps command are not dynamically consecutive. to monitor the process time, use the top tool.
The ps command in Linux is short for Process Status. The ps command is used to list the processes currently running in the system. The ps command lists the snapshots of the current processes, that is, those processes that run the ps command at that time. if you want to dynamically display process information, you can use the top command. To monitor and control processes, you must first understand the current process, that is, you need to view the current process, and the ps command is the most basic and very powerful process viewing command. You can use this command to determine which processes are running and running, whether the process is terminated, whether the process is dead, and which processes are occupying excessive resources. In short, most of the information can be obtained by executing this command.
Ps provides a one-time view of the process. The results are not dynamically consecutive. to monitor the process time, use the top tool.
The kill command is used to kill a process.
There are five processes in linux:
1. run (running or waiting in the running queue)
2. interruption (in sleep, blocked, waiting for the formation or receipt of a signal of a condition)
3. do not interrupt (do not wake up when receiving the signal or do not run, the process must wait until there is an interruption)
4. Stiff (the process has been terminated, but the process descriptor exists until the parent process calls wait4 () and is released after the system call)
5. stop (the process stops running after receiving signals from SIGSTOP, SIGSTP, SIGTIN, and SIGTOU)
Five status codes used by the PS tool to identify a process:
D. uninterruptible sleep (usually IO) cannot be interrupted)
R run runnable (on run queue)
S interrupt sleeping
T stop traced or stopped
Z dead a defunct ("zombie") process
1.Command format:
Ps [Parameters]
2. command functions:
Used to display the status of the current process
3. command parameters:
A. all processes are displayed.
-A: displays all programs on the same terminal.
-A: displays all processes.
C. display the real name of the process
-N reverse selection
-E equals to "-"
E. display environment variables
F. display the relationship between programs.
-H: Display tree structure
R displays the process of the current terminal
T display all programs of the current terminal
All processes of the user specified by u
-Au displays more detailed information
-Aux: show all itineraries containing other users
-C <命令> Lists the status of a specified command.
-- Lines <行数> Number of lines per page
-- Width <字符数> Number of characters displayed per page
-- Help: displays help information.
-- Display version
4.Use instance:
Instance 1: displays information about all processes.
Command: ps-
Output:
Copy codeThe code is as follows:
[Root @ localhost test6] # ps-
PID TTY TIME CMD
1? 00:00:00 init
2? 00:00:01 migration/0
3? 00:00:00 ksoftirqd/0
4? 00:00:01 migration/1
5? 00:00:00 ksoftirqd/1
6? 00:29:57 events/0
7? 00:00:00 events/1
8? 00:00:00 khelper
49? 00:00:00 kthread
54? 00:00:00 kblockd/0
55? 00:00:00 kblockd/1
56? 00:00:00 kacpid
217? 00:00:00 cqueue/0
Note:
Instance 2: displays the specified user information
Command: ps-u root
Output:
Copy codeThe code is as follows:
[Root @ localhost test6] # ps-u root
PID TTY TIME CMD
1? 00:00:00 init
2? 00:00:01 migration/0
3? 00:00:00 ksoftirqd/0
4? 00:00:01 migration/1
5? 00:00:00 ksoftirqd/1
6? 00:29:57 events/0
7? 00:00:00 events/1
8? 00:00:00 khelper
49? 00:00:00 kthread
54? 00:00:00 kblockd/0
55? 00:00:00 kblockd/1
56? 00:00:00 kacpid
Note:
Instance 3: displays information about all processes, together with the command line
Command: ps-ef
Output:
Copy codeThe code is as follows:
[Root @ localhost test6] # ps-ef
UID PID PPID C STIME TTY TIME CMD
Root 1 0 0 Nov02? 00:00:00 init [3]
Root 2 1 0 Nov02? 00:00:01 [migration/0]
Root 3 1 0 Nov02? 00:00:00 [ksoftirqd/0]
Root 4 1 0 Nov02? 00:00:01 [migration/1]
Root 5 1 0 Nov02? 00:00:00 [ksoftirqd/1]
Root 6 1 0 Nov02? 00:29:57 [events/0]
Root 7 1 0 Nov02? 00:00:00 [events/1]
Root 8 1 0 Nov02? 00:00:00 [khelper]
Root 49 1 0 Nov02? 00:00:00 [kthread]
Root 54 49 0 Nov02? 00:00:00 [kblockd/0]
Root 55 49 0 Nov02? 00:00:00 [kblockd/1]
Root 56 49 0 Nov02? 00:00:00 [kacpid]
Note:
Example 4: common combinations of ps and grep to find specific processes
Command: ps-ef | grep ssh
Output:
Copy codeThe code is as follows:
[Root @ localhost test6] # ps-ef | grep ssh
Root 2720 1 0 Nov02? 00:00:00/usr/sbin/sshd
Root 17394 2720 0? 00:00:00 sshd: root @ pts/0
Root 17465 17398 0 00:00:00 pts/0 grep ssh
Note:
Instance 5: list the current PID and related information for your login
Command: ps-l
Output:
Copy codeThe code is as follows:
[Root @ localhost test6] # ps-l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 17398 17394 0 75 0-16543 wait pts/0 00:00:00 bash
4 R 0 17469 17398 0 77 0-15877-pts/0 00:00:00 ps
Note:
Meanings of relevant information:
F indicates the flag of the program. 4 indicates that the user is super user.
S represents the state of the program (STAT). The meaning of each STAT will be described in the article.
The UID program is owned by the UID.
PID is the ID of this program!
PPID is the ID of the parent program.
Percentage of c cpu resources used
PRI is the abbreviation of Priority (Priority execution order ).
NI: Nice value. we will continue to introduce it in the next section.
ADDR is the kernel function, indicating the part of the program in the memory. If it is a running program, it is generally "-"
Memory used out by SZ
Is the program currently running? if-indicates it is running
TTY login terminal location
Cpu time used out.
What are the commands issued by CMD?
Under the preset conditions, ps only lists the PID related to the current bash shell. Therefore, when I use ps-l, there are only three PIDs.
Instance 6: list all programs currently in memory
Command: ps aux
Output:
Copy codeThe code is as follows:
[Root @ localhost test6] # ps aux
User pid % CPU % MEM VSZ RSS TTY STAT START TIME COMMAND
Root 1 0.0 0.0 10368 676? Ss Nov02 0: 00 init [3]
Root 2 0.0 0.0 0 0? S <Nov02 0: 01 [migration/0]
Root 3 0.0 0.0 0 0? SN Nov02 0: 00 [ksoftirqd/0]
Root 4 0.0 0.0 0 0? S <Nov02 0: 01 [migration/1]
Root 5 0.0 0.0 0 0? SN Nov02 0: 00 [ksoftirqd/1]
Root 6 0.0 0.0 0 0? S <Nov02 29:57 [events/0]
Root 7 0.0 0.0 0 0? S <Nov02 0: 00 [events/1]
Root 8 0.0 0.0 0 0? S <Nov02 0: 00 [khelper]
Root 49 0.0 0.0 0 0? S <Nov02 0: 00 [kthread]
Root 54 0.0 0.0 0 0? S <Nov02 0: 00 [kblockd/0]
Root 55 0.0 0.0 0 0? S <Nov02 0: 00 [kblockd/1]
Root 56 0.0 0.0 0 0? S <Nov02 0: 00 [kacpid]
Note:
USER: The process belongs to the USER account
PID: Number of the process
% CPU: Percentage of CPU resources used by the process
% MEM: Percentage of physical memory occupied by the process
VSZ: virtual memory used by the process (Kbytes)
RSS: the fixed amount of memory occupied by the process (Kbytes)
TTY: The process operates on that terminal. if it is irrelevant to the terminal, it will display ?, In addition, the tty1-tty6 is the login program on the machine, if the pts/0 and so on, it indicates the program connected to the host by the network.
STAT: the current state of the program. The main states are:
R: The program is currently running or can be operated.
S: The program is currently in sleep (or idle state), but can be awakened by some signals (signal.
T: The program is currently detecting or stopping
Z: The program should have been terminated, but its parent program cannot terminate it normally, resulting in the state of zombie (zombie) program.
START: the time when the process is triggered.
TIME: The actual CPU usage TIME of the process.
COMMAND: The actual COMMAND of the program.
Instance 7: Program display listing similar Program trees
Command: ps-axjf
Output:
Copy codeThe code is as follows:
[Root @ localhost test6] # ps-axjf
Warning: bad syntax, perhaps a bogu '-'? See/usr/share/doc/procps-3.2.7/FAQ
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
0 1 1 1? -1 Ss 0 0: 00 init [3]
1 2 1? -1 S <0 0: 01 [migration/0]
1 3 1? -1 SN 0: 00 [ksoftirqd/0]
1 4 1 1? -1 S <0 0: 01 [migration/1]
1 5 1 1? -1 SN 0: 00 [ksoftirqd/1]
1 6 1? -1 S <0 29:58 [events/0]
1 7 1 1? -1 S <0 0: 00 [events/1]
1 8 1 1? -1 S <0 0: 00 [khelper]
1 49 1 1? -1 S <0 0: 00 [kthread]
49 54 1 1? -1 S <0 0: 00 \ _ [kblockd/0]
49 55 1 1? -1 S <0 0: 00 \ _ [kblockd/1]
49 56 1 1? -1 S <0 0: 00 \ _ [kacpid]
Note:
Instance 8: Find the PID numbers related to the cron and syslog services.
Command: ps aux | egrep '(cron | syslog )'
Output:
Copy codeThe code is as follows:
[Root @ localhost test6] # ps aux | egrep '(cron | syslog )'
Root 2682 0.0 0.0 83384 2000? Sl Nov02 0: 00/sbin/rsyslogd-I/var/run/syslogd. pid-c 5
Root 2735 0.0 0.0 74812 1140? Ss Nov02 0: 00 crond
Root 17475 0.0 0.0 61180 832 pts/0 S + egrep (cron | syslog)
[Root @ localhost test6] #
Other instances:
1. you can use | the MPs queue is connected to more for pagination.
Command: ps-aux | more
2. display all the processes and output them to the ps001.txt file.
Command: ps-aux> ps001.txt
3. output the specified field
Command: ps-o pid, ppid, pgrp, session, tpgid, comm
Output:
Copy codeThe code is as follows:
[Root @ localhost test6] # ps-o pid, ppid, pgrp, session, tpgid, comm
PID PPID PGRP SESS TPGID COMMAND
17398 17394 17398 17398 bash
17478 17398 17478 17398 17478 ps
[Root @ localhost test6] #