ps aux
Display processes started by other users (a)
View your own processes in the system (x)
The user who started this process and the time it started ( u)
Use the "date -s" command to modify the system time
For example, the command to set the system time to June 10, 1996 is as follows.
#date -s 06/10/96
The command to set the system time to 1:12:00 pm is as follows.
#date -s 13:12:00
-------------------------------- -----------------------
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
COMMAND
root 1
0.0 0.0 1340 440
?
S Nov05 0:04
init
root 2
0.0 0.0
0
0
? SW Nov05
0:00 [keventd]
root 3
0.0 0.0
0
0 ?
SW Nov05 0:00 [keventd]
...
--------------------------------- ---------------------
USER domain indicates which user started this command;
Users can check the usage of a certain process How many CPUs;
Memory usage and its VSZ (virtual memory size) and RSS (resident set size):
VSZ indicates how much memory space a program needs to occupy if it is completely resident in memory;
RSS specifies shows how much memory is actually currently occupied;
STAT shows the current status of the process:
"S": The process is in a sleep state, indicating that these processes are waiting for certain events to occur - possibly user input or system resources. Availability;
The last command can effectively view system login events
After a process calls exit, the process does not disappear immediately, but remains A data structure called a zombie process (Zombie). Among the 5 states of Linux processes, zombie processes It is a very special kind. It has given up almost all memory space, does not have any executable code, and cannot be scheduled. It only reserves a position in the process list to record the exit status and other information of the process for other purposes. Process collection, except that zombie processes no longer occupy any memory space.
The function of the exit system call is to make the process exit, but it is only limited to turning a normal process into a zombie process and cannot completely destroy it.
Once a process calls wait, it immediately blocks itself. Wait automatically analyzes whether a child process of the current process has exited. If it finds such a child process that has become a zombie, wait
It will collect the information of this sub-process, destroy it completely and return; if no such sub-process is found, wait will block here until one appears.
Reprint STAT explanation in ps aux Collection
Run ps aux to get the following information:
ps aux
USER
PID %CPU %MEM
VSZ RSS
TTY
STAT START TIME COMMAND
smmsp 3521
0.0
0.7
6556
1616
?
Ss
20:40 0:00 sendmail: Queue runner@01:00:00 f
root
3532
0.0
0.2
2428
452
?
Ss
20:40 0:00 gpm -m /dev/input/mice -t imps2
htt
3563
0.0
0.0
2956
196
?
Ss
20:41 0:00 /usr/sbin/htt -retryonerror 0
htt
3564
0.0
1.7 29460
3704
?
Sl
20:41 0:00 htt_server -nodaemon
root
3574
0.0
0.4
5236
992
?
Ss
20:41 0:00 crond
xfs
3617
0.0
1.3 13572
2804
?
Ss
20:41 0:00 xfs -droppriv -daemon
root
3627
0.0
0.2
3448
552
?
SNs
20:41 0:00 anacron -s
root
3636
0.0
0.1
2304
420
?
Ss
20:41 0:00 /usr/sbin/atd
dbus
3655
0.0
0.5 13840
1084
?
Ssl
20:41 0:00 dbus-daemon-1 --system
............................. ...
The parameters in stat have the following meanings:
D Uninterruptible (usually
IO)
R Running, or process in the queue
S Sleeping state
T Stopped or tracked
Z Zombie process
W Enters memory swap (invalid starting from kernel 2.6)
X Dead process
< High priority
n Low priority
s contains child processes
+ Process group located in the background
========================== ============
ps command
To monitor and control the process, you must first understand the situation of the current process, that is, you need to view the current process, and the ps command is the most basic and also very powerful process viewing command. Use this command Can
Determine which processes are running and their running status, whether the process has ended, whether there are zombies in the process, which processes occupy too many resources, etc. In short, most of the information can be obtained by executing this command.
ps command The most commonly used one is to monitor the working status of the background process, because the background process does not communicate with 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 displays all programs.
3) When ps c lists programs, the real instruction name of each program is displayed, without including the path, parameters or identification of resident services.
4) ps -e The effect of this parameter is the same as specifying the "A" parameter.
5) When ps e lists programs, display the environment variables used by each program.
6) ps f uses ASCII characters to display the tree structure and express the relationship between programs.
7) ps -H displays a tree structure, indicating the relationship between programs.
8) ps -N displays all programs, except the programs under the terminal that execute the ps command.
9) ps s uses the program signal format to display the program status.
10) ps S includes interrupted subroutine information when listing programs.
11) ps -t
12) ps u Displays the program status in a user-oriented format.
13) ps x Displays all programs, not distinguished by terminal.
The most commonly used method is ps -aux, and then use a pipe symbol to direct grep to find a specific process, and then operate on the specific process.
There are 5 states of processes on Linux:
1. Running (running or waiting in the run queue)
2. Interrupted (sleeping, blocked, waiting) The formation of a certain condition or the receipt of a signal)
3. Uninterruptible (the signal will not wake up and cannot be run, the process must wait until an interrupt occurs)
4. Zombie (the process has terminated, but the process descriptor Exists until the parent process calls the wait4() system call and is released)
5. Stop (the process stops running after receiving SIGSTOP, SIGSTP, SIGTIN, SIGTOU signals)
5 types of ps tools to identify processes Status code:
D uninterruptible sleep (usually IO)
R runnable (on run queue)
S interrupt sleeping
T stop traced or stopped
Z zombie 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 the process status:
ps -eo user,stat..,cmd
user user name
uid user number
pid process number
ppid parent process number
size memory size, Kbytes bytes.
vsize total virtual memory size, bytes bytes (including code+data+stack)
share total sharing Number of pages
nice process priority (default is 0, maximum is -20)
priority(pri) kernel scheduling priority
pmem percentage of physical memory shared by the process
trs program execution code Residency size
rss The total physical memory used by the process, Kbytes bytes
time The total CPU temporary time since the process was executed
stat Process status
cmd(args) Simple command execution Format
Example:
View the uid, pid, stat, pri of the current system process, sort by uid number.
ps -eo pid,stat,pri,uid –sort uid
View the user, pid, stat, rss, args of the current system process, sorted by rss.
ps -eo user, pid, stat, rss, args –sort rss
Name: ps
Usage permission: all users
Usage method: ps [options] [--help]
Description: Display the dynamics of the instantaneous journey (process)
Parameters:
ps There are many parameters. Here we only list a few commonly used parameters and briefly introduce their meanings
-A List all itineraries
-w Display widening to display more information
-au Display larger Detailed information
-aux Displays all trips that include other users
au(x) Output format:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
USER: Trip owner
PID: pid
%CPU: Occupied CPU usage
%MEM: Occupied memory usage
VSZ: Occupied virtual memory size
RSS : Memory size occupied
TTY: Minor device number of tty
STAT: Status of the trip:
D: Uninterruptible static
R: Executing Medium
S: Quiescent state
T: Suspended execution
Z: Does not exist but cannot be eliminated at the moment
W: Not enough memory pages can be allocated
<: High-priority itinerary
N: Low-priority trip
L: Memory pages are allocated and locked in the memory
START: Trip start time
TIME: Execution time
COMMAND: Executed command
example:
ps
PID TTY TIME CMD
2791 ttyp0 00:00:00 tcsh
3092 ttyp0 00:00:00 ps
% ps -A
PID TTY TIME CMD
1 ? 00:00:03 init
2 ? 00:00:00 kflushd
3 ? 00:00:00 kpiod
4 ? 00:00:00 kswapd
5 ? 00:00:00 mdrecoveryd
..........
% ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.7 1096 472 ? S Sep10 0:03 init [3]
root 2 0.0 0.0 0 0 ? SW Sep10 0:00 [kflushd]
root 3 0.0 0.0 0 0 ? SW Sep10 0:00 [kpiod]
root 4 0.0 0.0 0 0 ? SW Sep10 0:00 [kswapd]
.....
To monitor and control the process, you must first understand the situation of the current process, that is, you need to view the current process, and ps
The command is the most basic but also very powerful process viewing command. Use this command to determine which processes are running and their running status, whether the process has ended, whether the process has died, which processes are occupying too many resources, and so on. In short, most of the information can be obtained by executing this command.
ps provides us with a one-time view of the process, but the view results it provides are not dynamic and continuous; if you want to monitor the process time, you should use the top tool.
kill is used to kill the process.
1. Parameter description of ps
ps provides a lot of option parameters, the following are commonly used:
l Long format output;
u Press user name and startup time to display processes in the order;
j uses task format to display processes;
f uses tree format to display processes;
a displays all processes of all users (including other users);
x displays processes without a controlled terminal;
r displays running processes;
ww avoids detailed parameters being truncated;
Our commonly used options are the combination of aux or lax, and the parameter f Applications.
2. Explanation of ps aux or lax output
USER process owner;
PID process ID;
PPID parent process;
%CPU percentage of CPU occupied by the process;
%MEM is the percentage of memory occupied;
NI is the NICE value of the process. Larger values mean less CPU time is occupied;
VSZ is the virtual size of the process;
RSS is the number of resident pages;
TTY Terminal ID
STAT process status (there are the following types)
D Uninterruptible sleep state (usually IO process);
R Running and available in the queue. ;
S is in sleep state;
T is stopped or tracked;
W enters memory swapping (invalid since kernel 2.6);
X dead process (never seen);
Z Zombie process;
< High priority process
N Lower priority process
L Some pages are locked into memory;
s The leader of the process (in which There are child processes under it);
l Multi-process (using CLONE_THREAD, similar to NPTL pthreads);
+ Process group located in the background;
WCHAN is waiting for process resources;
START starts the process Time;
TIME process consumes CPU time;
COMMAND command name and parameters;
3. Application examples
[root@localhost ~]# ps -aux |more
You can use | pipe and more to connect to view in pages.
[root@localhost ~]# ps -aux > ps001.txt
[root@localhost ~]# more ps001.txt
Here all processes are displayed and output to the ps001.txt file , and then use more to view it in pages.
4. Kill terminates the process
There are more than a dozen ways to control the process. Here are some commonly used methods:
kill -STOP [pid]
Send SIGSTOP (17,19,23 ) stops a process without killing it.
kill -CONT [pid]
Send SIGCONT (19,18,25) to restart a stopped process.
kill -KILL [pid]
Send SIGKILL (9) to force the process to stop immediately and do not implement cleanup operations.
kill -9 -1
Kill all processes you own.
SIGKILL and SIGSTOP signals cannot be caught, blocked, or ignored, but other signals can. So this is your ultimate weapon.
For more detailed explanations of ps aux and related articles, please pay attention to the PHP Chinese website!