Linux technology learning: how to view the process ps

To monitor and control the process, 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. Use this command to determine which processes are running and The running status, whether the process ends, whether the process has zombies, which processes occupy too many resources, etc. In short, most of the information can be obtained by executing this command.

The ps command is most commonly used to monitor the work of the background process, because the background process does not communicate with the standard input/output devices such as the screen keyboard, so if you need to detect its situation, you can use the ps command.

1) ps a Displays all programs under the current terminal, including programs of other users.

2) ps -A shows all programs.

3) When ps c lists programs, it displays the real command name of each program, without the path, parameter or resident service sign.

4) ps -e The effect of this parameter is the same as specifying the "A" parameter.

5) When ps e lists programs, it shows the environment variables used by each program.

6) ps f Use ASCII characters to display the tree structure to express the relationship between programs.

7) ps -H displays a tree structure, indicating the relationship between programs.

8) ps -N displays all programs, except for the programs under the ps command terminal.

9) ps s Displays the program status in the format of program signal.

10) When ps S lists programs, it includes interrupted subprogram data.

11) ps -t <terminal number> Specify the terminal number and list the status of the programs belonging to the terminal.

12) ps u displays the program status in a user-based format.

13) ps x displays all programs, not differentiated by terminals.

The most common method is ps -aux, and then use a pipe symbol to guide grep to find a specific process, and then operate on a specific process.

There are 5 states of a process on linux:

  1. running (running or waiting in the run queue)

  2. Interrupt (sleeping, blocked, waiting for a condition to form or to receive a signal)

  3. Uninterruptible (does not wake up and cannot run when a signal is received, the process must wait until an interrupt occurs)

  4. Zombie (process terminated, but the process descriptor exists until released after the parent process calls the wait4() system call)

  5. Stop (the process stops running after receiving SIGSTOP, SIGSTP, SIGTIN, SIGTOU signals)

The ps tool identifies five status codes of the process:

D uninterruptible uninterruptible sleep (usually IO)

R 运行 runnable (on run queue)

S interrupt sleeping

T 停止 traced or stopped

Z 僵死 a defunct (”zombie”) process

Note: Other states include W (no resident page), < (high priority process), N (low priority process), L (memory lock page).

Use ps format output to view process status:

ps -eo user,stat..,cmd

user username

uid User ID

pid Process ID

ppid parent process ID

size memory size, Kbytes bytes.

vsize total virtual memory size, bytes (including code+data+stack)

share Total number of shared pages

nice process priority (default is 0, maximum is -20)

priority(pri) kernel scheduling priority

Percentage of physical memory shared by pmem processes

trs program execution code residency size

The total physical memory used by the rss process, Kbytes bytes

time The total CPU temporary time from the execution of the process until now

stat process status

cmd(args) Simple format for executing the command

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325336342&siteId=291194637