The ps command is the most commonly used command to monitor processes. Through this command, you can view detailed information about all running processes in the system.
The basic format of the ps command is as follows:
[root@localhost ~]# ps aux
#View all processes in the system, using the BS operating system format
[root@localhost ~]# ps -le
#View all processes in the system, using the Linux standard command format
Options:
- a: Display all processes of a terminal, except session leads;
- u: Displays the user belonging to the process and memory usage;
- x: Display processes that do not control the terminal;
- -l: Long format displays more detailed information;
- -e: Display all processes;
The ps command is somewhat different. Some of its options cannot include "-", such as the command "ps aux", where "aux" is an option, but "-" cannot be included in front.
【Example 1】
[root@localhost ~]# ps aux #View all processes in the system USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.2 2872 1416 ? Ss Jun04 0:02 /sbin/init root 2 0.0 0.0 0 0 ? S Jun04 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Jun04 0:00 [migration/0] root 4 0.0 0.0 0 0 ? S Jun04 0:00 [ksoftirqd/0] …omitted…
Table 1 lists the specific meanings of each column in the above output information.
Header | meaning |
---|---|
USER | Which user created this process. |
PID | The ID of the process. |
%CPU | The percentage of CPU resources occupied by the process. The higher the percentage occupied, the more resources the process consumes. |
%MEM | The percentage of physical memory occupied by the process. The higher the percentage occupied, the more resources the process consumes. |
VSZ | The size of the virtual memory occupied by this process, in KB. |
RSS | The actual physical memory size occupied by the process, in KB. |
TTY | In which terminal the process is running. Among them, tty1 ~ tty7 represent local console terminals (different terminals can be switched through Alt+F1 ~ F7 shortcut keys), tty1 ~ tty6 are local character interface terminals, and tty7 is a graphical terminal. pts/0 ~ 255 represents a virtual terminal, usually a remote connection terminal. The first remote connection occupies pts/0, and the second remote connection occupies pts/1, which increases in sequence. |
STAT | Process status. Common statuses include the following:
|
START | The start time of this process. |
TIME | This process occupies CPU computing time, note that it is not system time. |
COMMAND | The name of the command that spawned this process. |
[Example 2] The "ps aux" command can see all the processes in the system, and the "ps -le" command can also see all the processes in the system. Due to the "-l" option, the "ps -le" command can see more detailed information, such as the PID and priority of the parent process. But the basic functions of these two commands are the same, and mastering one of them is enough.
[root@localhost ~]# ps -le F S UID PID PPID C PRI Nl ADDR SZ WCHAN TTY TIME CMD 4 S 0 1 0 0 80 0 - 718 - ? 00:00:02 init 1 S 0 2 0 0 80 0 - 0 - ? 00:00:00 kthreadd 1 S 0 3 2 0 -40 - - 0 - ? 00:00:00 migration/0 1 S 0 4 2 0 80 0 - 0 - ? 00:00:00 ksoflirqd/0 1 S 0 5 2 0 -40 - - 0 - ? 00:00:00 migration/0 …省略…
Table 2 lists the meaning of each column in the above output information.
Header | meaning |
---|---|
F | Process flags indicate the permissions of the process. There are two common flags:
|
S | Process status. The specific status is consistent with the STAT status in the "psaux" command; |
UID | The ID of the user running this process; |
PID | Process ID; |
PPID | The ID of the parent process; |
C | The CPU usage of the process, the unit is percentage; |
AT | The priority of the process. The smaller the value, the higher the priority of the process and the earlier it is executed by the CPU; |
IN | The priority of the process, the smaller the value, the earlier the process is executed; |
ADDR | Where in memory is the process located? |
SZ | How much memory does the process occupy? |
WCHAN | Whether the process is running. "-" means running; |
TTY | 该进程由哪个终端产生; |
TIME | 该进程占用 CPU 的运算时间,注意不是系统时间; |
CMD | 产生此进程的命令名; |
【例 3】如果不想看到所有的进程,只想查看一下当前登录产生了哪些进程,那只需使用 "ps -l" 命令就足够了:
[root@localhost ~]# ps -l #查看当前登录产生的进程 F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 18618 18614 0 80 0 - 1681 - pts/1 00:00:00 bash 4 R 0 18683 18618 4 80 0 - 1619 - pts/1 00:00:00 ps