Linux Process management in process ps How to use commands ,kill How to use , How to end the background process


Process management


The life cycle of a process :

The main process pid Generally, the subprocess will process the received data , Subprocesses ppid After processing, you can give the returned result to the main process , If the main process dies in the process , Then the child process becomes a zombie process ; The child process has no effect on the main process .


Command to monitor the process ps


ps -aux
a # all View all terminal processes
x #  View all non terminal processes
u # user    Who are the users of this process
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.3 125304  3832 ?        Ss   06:23   0:02 /usr/lib/systemd/systemd --switched-
root          2  0.0  0.0      0     0 ?        S    06:23   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    06:23   0:02 [ksoftirqd/0]
USER          The user who started the process
PID  Process pid Number
%CPU  Occupy cpu Percent of
%MEM     Percentage of memory used
VSZ   Virtual memory  ( Virtual memory occupied by process )
RSS  Real physical memory  ( Processes take up real memory space )
TTY Running Terminal
? The terminal on which the kernel runs
tty1   The terminal at which the machine runs
pts/0 Remote connected terminals
STAT State of process
D Unable to sleep the terminal ( and i/o The process involved )
R Running programs
S Dormant
T The state of being suspended or tracked
W Into switched memory
X Dead process
Z Zombie process
< High priority processes
N Low priority processes
s Parent process and child process
l Run as a thread
L Some pages are locked into memory
| Multi process
+ Running programs
START  The time the process was triggered to start
TIME The process actually uses cpu Running time of
COMMAND The start command of the process is
--sort
ps aux --sort=%cpu
USER        
PID 
%CPU 
%MEM    
VSZ   
RSS 
TTY     
STAT 
START   
TIME 
COMMAND
 
A sort method ,sort= The content of the command must be the result of the command . + -  It can be in order or reverse
[[email protected]_nginx ~]# ps axo user,pid,%cpu,%mem,command
See the process for additional commands
pgrep
[[email protected]_nginx ~]# pgrep nginx
pgrep -l -a
pidof
[[email protected]_nginx ~]# pidof nginx
[[email protected]_nginx ~]# yum -y install psmisc
pstree  command , You can view child processes
grep Filtering process does not show grep
ps -ef | grep [n]ginx


kill- Signal management


kill 
pkill 
killall
kill
-l #  Look at the signal
[[email protected]_nginx ~]# kill -l
 1) SIGHUP  2) SIGINT  3) SIGQUIT  4) SIGILL  5) SIGTRAP
 6) SIGABRT  7) SIGBUS  8) SIGFPE  9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
List of common signals
digital signal Signal alias effect
1 HUP Hang signal , It's often possible to reconfigure the process
kill -s HUP
kill -1
2 INT Interrupt signal , It's the end of it , and ctrl+c It does the same thing
kill -s INT
kill -2
3 QUIT Let the process exit , The result is that the process exits
kill -s QUIT
kill -3
9 KILL End the process directly , Cannot be captured by a process
kill -s KILL
kill -9
15 TERM Process termination , This is the default signal
kill -15
kill -s TERM
kill
18 CONT The suspended process will resume running
19 STOP Pause the process
20 TSTP The user stops the request , Function like ctrl+z Put the process in the background and pause 


Priority of the process


The lower the number, the higher the priority

# nice
-n #  Assign priority , It's when the program starts , Assign priority
[[email protected] ~]# nice -n -20 tail -f /var/log/messages
# renice
[[email protected] ~]# ps axo nice,command|grep sshd
[[email protected] ~]# renice 19 9962


Background process management


& #  Put the process in the background
ctrl + z #  Pause
bg: #  Put it backstage
fg: #  Call out
screen
#  Create a new background process
[[email protected]_nginx ~]# screen
#  Specify the name of the background process
[[email protected]_nginx ~]# screen -S ping
ctrl+ad  Return to terminal
#  Check the background process
[[email protected]_nginx ~]# screen -ls
#  View background processes
[[email protected]_nginx ~]# screen -r 20068
nohup
[[email protected]_nginx ~]# nohup sh a.sh &