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:
- Running (running or waiting in the running queue)
- Interrupt (dormant, blocked, waiting for a condition to form or receive a signal)
- Non-interruptible (Received signal does not wake up and cannot be run, process must wait until interrupt occurs)
- Zombie (The process has been terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released)
- Stop (process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running)
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
1. Command Format
ps[parameters]
2. Command function
Used to display the status of the current process
3. Command Parameters
a
Show All Processes
-a
Show All programs under the same terminal
-A
Show All Processes
c
Show the real name of the process
-N
Reverse Selection
-e
equals "-A"
e
Display environment variables
f
Show relationships between programs
-H
Show tree structure
r
Show process for current terminal
T
Show All programs for the current terminal
u
Specify all processes for a user
-au
Show more detailed information
-aux
Show all itineraries that contain other users
-C
< commands > lists the status of the specified command
--lines
< rows > number of rows displayed per page
--width
< number of characters > characters displayed per page
--help
Display Help information
--version
Show version Show instance 1: Show all process information commands:ps -A
Example 2: Display the specified user information command:ps -u root
Example 3: Show all process information, along with command-line commands:ps -ef
Example 4:ps with grep common use combination to find specific process commands:ps -ef|grep ssh
ps -lF S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD0 S 1000 2168 2167 0 80 0 - 28869 wait pts/0 00:00:00 bash
Shelldescribe the meaning of the relevant information:
F
Flag for this program, 4 for user Super User
S
Represents the status of this program (STAT), and the significance of each stat will be described in the text
UID
The program is owned by the UID
PID
That's the ID of the program.
PPID
is the ID of its ancestor parent program
C
Percent of resources used by the CPU
PRI
This is the abbreviation for priority (precedence order), which is described in detail later
NI
This is a nice value, and in the next section we will continue to introduce
ADDR
This is the kernel function, which indicates the part of the program that is in the memory. If it's a running program, it's usually "-"
SZ
Memory size to use
WCHAN
Whether the procedure is currently in operation, if it is-indicates that it is operating
TTY
Terminal location of the logged-in person
TIME
The CPU time that was used off.
CMD
What is the order issued?
In the case of a preset,ps
Only the PID associated with the bash shell currently in place is listed, so when I use theps -l
, there are only three PID.Example 6: List all currently in-memory programsCommand:ps aux
Output:[[email protected] ~]$ ps auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.1 0.3 125084 3612 ? Ss 19:58 0:03 /usr/lib/syste..
Description:
USER
: The process belongs to that user account
PID
: The number of the process
%CPU
: Percentage of CPU resources that the process uses
%MEM
: Percentage of physical memory occupied by this process
VSZ
: The amount of virtual memory that the process uses (Kbytes)
RSS
: The amount of fixed memory that the process occupies (Kbytes)
TTY
: The process is operating on that terminal, and if it is not related to the terminal, it will be displayed?, in addition, tty1-tty6
Is the computer above the login program, if pts/0, and so on, is represented by the network connected to the host computer program.
STAT
: The current state of the program, the main state has
R
: The program is currently in operation or can be operated
S
: The program is currently sleeping (which can be said to be idle) but can be awakened by certain signals (signal).
T
: The program is currently detecting or stopping
Z
: The program should have been terminated, but the parent program could not properly terminate him, causing the state of the zombie (Xinjiang Corpse) program
START
: The time that the process was triggered to start
TIME
: The time that the process actually uses the CPU to operate
COMMAND
: The actual instruction of the program
- Example 7: List programs that resemble the program tree display commands:
ps -axjf
Example 8: Find out the PID number command execution and output related to cron and syslog services: ps aux | egrep ‘(cron|syslog)‘
- Example 9 (Other):1. Can be used | Pipe and more connect up paging view
Command:ps -aux |more
Shell2. Show all the processes and output to the Ps001.txt file
Command:ps -aux > ps001.txt
Shell3. Outputs the specified field
Command: ps -o pid,ppid,pgrp,session,tpgid,comm
Shell Record-shell Script Basics (v)