Process Management--Terminate process
1. Kill command
[[Email protected] ~] #kill-L
#查看可用的进程信号
|
Signal Code |
Signal Name |
Description |
|
1 |
SIGHUP |
This signal enables the process to shut down immediately and then restarts after the configuration file is read again. |
|
9 |
SIGFPE |
Used to immediately end the operation of the program, this signal can not be blocked, processed and ignored. Typically used to force a process to terminate. |
|
15 |
SIGTERM |
The signal of the normal end process, the default signal of the KILL command. Sometimes if the process has been a problem, this signal is unable to terminate the process normally, we will try to sigkill signal, that is, signal 9. |
1 is actually restarting the service, and service Apache Restart actually calls the 1 signal;
9 for Force termination 15 is normal termination
Example: [[email protected] ~] #kill-1 22354
#重启进程
[[Email protected] ~] #kill-9 22368
#强制杀死进程
Example: [Email protected] ~]$ pstree-p |grep httpd
|-HTTPD (1065)-+-httpd (2285)
| |-HTTPD (2286)
| |-HTTPD (2287)
| |-HTTPD (2288)
| |-HTTPD (2289)
[[email protected] ~]$ sudo kill-9 2287 forced removal process
[Email protected] ~]$ pstree-p |grep httpd
|-HTTPD (1065)-+-httpd (2285)
| |-HTTPD (2286)
| |-HTTPD (2288)
| |-HTTPD (2289)
| '-httpd (5498)
[[email protected] ~]$ sudo kill-1 1065 Restart main process
[Email protected] ~]$ pstree-p |grep httpd
|-HTTPD (1065)-+-httpd (5686)
| |-HTTPD (5687)
| |-HTTPD (5688)
| |-HTTPD (5689)
| '-httpd (5690)
2. Killall command
[[Email protected] ~] $killall [options] [signal] Process name
#按照进程名杀死进程
Options:
-I: Interactive, asking if you want to kill a process
-I ignores process name capitalization
Example: [[email protected] ~]$ sudo killall-9 httpd
[Email protected] ~]$ pstree-p |grep httpd
3. Pkill command
[[email protected] ~]$ pkill [options] [signal] Process name
#按进程名终止进程
Options:
-T terminal number: Kick the user according to the terminal number
Example: [[email protected] ~]$ sudo service httpd start
#启动httpd服务
[Email protected] ~]$ pstree-p |grep httpd
|-HTTPD (5826)-+-httpd (5827)
| |-HTTPD (5828)
| |-HTTPD (5829)
| |-HTTPD (5830)
| '-httpd (5831)
#查看httpd服务的进程
[email protected] ~]$ sudo pkill-9 httpd
#终止httpd服务进程
[Email protected] ~]$ pstree-p |grep httpd
#查看httpd的进程树, the discovery has been terminated.
a forced termination is a condition in which the normal stop means does not take effect. Under normal circumstances, starting the HTTPD service is still required to start This command with service httpd.
Example: [[email protected] ~]$ W #查看当前登录的用户数
17:41:01 up 2:34, 2 users, load average:0.00, 0.01, 0.05
USER TTY from [email protected] IDLE jcpu PCPU
Xiaofeng tty1 15:36 2:03m 0.15s 0.15s-bash
Xiaofeng pts/0 192.168.217.1 15:07 5.00s 0.25s 0.00s W
[[email protected] ~]$ sudo pkill-9-T tty1 kick the local login account
[Email protected] ~]$ W
17:41:54 up 2:35, 1 user, load average:0.00, 0.01, 0.05
USER TTY from [email protected] IDLE jcpu PCPU
Xiaofeng pts/0 192.168.217.1 15:07 2.00s 0.26s 0.00s W
#查看当前用户, found that Tty1 was kicked out
Process Management 2