Syntax Note:
The PS (process status) command comes in 2 different styles, namely BSD and UNIX. New users often confuse and interpret both styles in a wrong way. So to figure them out, before proceeding, here are some basic information.
Note: "PS aux" and "ps-aux" are not the same. Examples such as "-U" are used to display the user's process. But "U" is the display of detailed information.
BSD style: The BSD-style syntax option is not with hyphens before.
- PS aux
Unix/linux style: There is a dash in front of the Linux style syntax options as usual. ...
- Ps-ef
Mixing the syntax styles on two Linux systems is a good thing. such as "PS Ax-f". But in this article, we will focus primarily on UNIX-style syntax.
How do I use the PS command?
1. Show All Processes:
The following command lists all the processes:
- $ ps AX
- $ ps-ef
Add pipe output to less to scroll the display
"U" or "-F" parameter to display details of all processes
- $ ps aux
- $ ps-ef-f
Note: Why the user column does not display my user name, but shows other users, such as root, www, etc., for all usernames (including you) if the length is greater than 8 characters, then PS will only display the UID, not the user name.
3. Display the process by name and process ID:
Search for a process by name or command, using the "-C" option followed by a search term.
- $ ps-c Apache2
- PID TTY Time CMD
- 2359? 00:00:00 apache2
- 4524? 00:00:00 apache2
- 4525? 00:00:00 apache2
------------------------
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 and grep common use combination to find specific processes
Command:
Ps-ef|grep SSH
Linux PS command