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, which are those that are executing the PS command at the moment, and if you want to display process information dynamically, you can use the top command.
To monitor and control the process, you must first understand the current process, that is, you need to see the current process, and the PS command is the most basic and very powerful process view command. Use this command to determine which processes are running and running, whether the process is complete, if the process is zombie, which processes are consuming too many resources, and so on. In short, most of the information can be obtained by executing the command.
PS gives us a one-time view of the process, it provides a view of the results is not dynamic continuous, if you want to monitor the process, you should use the top tool.
The KILL command is used to kill the process.
There are 5 states of processes on Linux:
1. Running (running or waiting in the running queue)
2. Interrupt (dormant, blocked, waiting for a condition to form or receive a signal)
3. Non-interruptible (receive signal does not wake up and not run, process must wait until interrupt occurs)
4. Zombie (The process has been terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released)
5. Stop (process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running run)
PS Tool identifies 5 status codes for the process:
D non-interruptible uninterruptible sleep (usually IO)
R run runnable (on run queue)
S Interrupt Sleeping
T stop traced or stopped
Z Zombie a defunct ("zombie") process
PS command supports three types of syntax formats used
UNIX style, options can be grouped together, and the option must have "-" hyphens before
BSD style, options can be grouped together, but cannot have a "-" hyphen before the option
GNU style long option with two "-" hyphens in front of options
We can mix these styles, but there may be conflicts. This article uses the UNIX-style PS command.
Common parameters:
-a displays all programs under the same terminal,
-aux Show all processes that contain other users
Common option combinations:
1. Execute PS command without parameters
This is a basic PS to use. Execute this command from the console and view the results.
Execute PS command without option
The result is 4 columns of information displayed by default.
- PID: The process number of the command (CMD) running
- TTY: Where the command is running (terminal)
- Time: CPU processing times consumed by the command that is running
- CMD: The command that the process runs
This information is not sorted when it is displayed.
2. Show all current processes
Use the-a parameter. -a representsall. Plus the x parameter shows the process without the control terminal.
- $ PS -ax
The result of this command may be very long. For ease of viewing, it can be used in conjunction with less commands and pipelines.
- $ PS -ax | Less
PS All information
3. Based on user filtering process
We can use the- u parameter when we need to see a particular user process. For example, we want to see the user ' Pungki ' process, you can use the following command:
- $ PS -u pungki
Filter by user
4. Filtering processes through CPU and memory usage
You might want to filter the results by CPU or memory usage, so you can find which process is taking up your resources. To do this, we can use the aux parameter to display comprehensive information:
- $ PS -aux | Less
Show full information
When the results are long, we can use the pipe and less command to filter.
The default result set is not well-ordered. Can be sorted by --sort command.
Sort Ascending According to CPU usage
- $ PS -aux --sort -pcpu | Less
Sort by CPU usage
Sort Ascending According to memory usage
- $ PS -aux --sort -pmem | Less
Sort by memory usage
We can also merge them into one command and display the top 10 results by pipeline:
$ PS -aux --sort -pcpu, +pmem | head -n ten
Resources:
1. https://linux.cn/article-4743-1.html
2. http://www.cnblogs.com/peida/archive/2012/12/19/2824418.html
"Linux Commands and Tools" PS