1. Command format:
kill[参数][进程号]
2. Command function:
Sends the specified signal to the corresponding process. Not specifying a model will send Sigterm (15) to terminate the specified process. Such as
Can not terminate the program can be used "-kill" parameter, which sends the signal is Sigkill (9), will be strong
Process, use the PS command or the jobs command to view the process number. The root user will affect the user's
Processes, non-root users can only affect their own processes.
3. Command parameters:
-l 信号,若果不加信号的编号参数,则使用“-l”参数会列出全部的信号名称-a 当处理当前进程时,不限制命令名和进程号的对应关系-p 指定kill 命令只打印相关进程的进程号,而不发送任何信号-s 指定发送信号-u
Attention:
1. Kill command can be with signal number option or without. If there is no signal number, the KILL command
A terminating signal (15) is emitted, which can be captured by the process, allowing the process to clean up before exiting
and release resources. You can also use kill to send a specific signal to the process. For example:
Kill-2 123
The effect is equivalent to pressing the CTRL + C key while the foreground is running the PID 123 process. However, ordinary users only
Can use the KILL command without the signal parameter or use a maximum of-9 signal.
2. Kill can have a process ID number as a parameter. When you send a signal to these processes with kill, it must be the
The master of some processes. If you attempt to revoke a process that does not have permission to revoke or revoke a process that does not exist
, you get an error message.
3, you can signal to multiple processes or terminate them.
4. When kill successfully sends a signal, the shell displays the process termination information on the screen. Sometimes
This message does not appear immediately, only if you press the ENTER key to make the Shell's command prompt reappear.
will show up.
5, it should be noted that the signal to force the process to terminate, which often brings some side effects, such as data loss or terminal
Unable to revert to a normal state. Be careful when sending a signal, only use the kill signal if it is a last resort
(9) Because the process cannot capture it first. To undo all background jobs, you can enter kill 0. Because
Some commands that run in the background start multiple processes, tracking and finding the PID of all the processes to be killed
It's a lot of trouble. At this point, using kill zero terminates all processes initiated by the current shell, which is a valid
Method.
4. Use instance: Example 1: List all signal names
命令:kill -l输出:[[email protected] test]# 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) SIGUSR213) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+439) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+843) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+1247) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-1451) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-1055) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-659) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-263) SIGRTMAX-1 64) SIGRTMAX
Description
Only the 9th signal (SIGKILL) can terminate the process unconditionally, other signal processes have the right to ignore.
下面是常用的信号:HUP 1 终端断线INT 2 中断(同 Ctrl + C)QUIT 3 退出(同 Ctrl + \)TERM 15 终止KILL 9 强制终止CONT 18 继续(与STOP相反, fg/bg命令)STOP 19 暂停(同 Ctrl + Z)
Example 2: Get the value of the specified signal
命令:kill -1输出:[[email protected] test]# kill -l KILL9[[email protected] test]# kill -l SIGKILL9[[email protected] test]# kill -l TERM15[[email protected] test]# kill -l SIGTERM
Example 3: First use PS to find the process, then kill with Kill
命令:kill 3268输出:[[email protected] test]# ps -ef|grep vim root 3268 2884 0 16:21 pts/1 00:00:00 vim install.logroot 3370 2822 0 16:21 pts/0 00:00:00 grep vim[[email protected] test]# kill 3268 [[email protected] test]# kill 3268 -bash: kill: (3268) - 没有那个进程
Example 4: Kill the process completely
命令:kill –9 3268 输出:[[email protected] test]# ps -ef|grep vim root 3268 2884 0 16:21 pts/1 00:00:00 vim install.logroot 3370 2822 0 16:21 pts/0 00:00:00 grep vim[[email protected] test]# kill –9 3268 [[email protected] test]# kill 3268 -bash: kill: (3268) - 没有那个进程
Example 5: Kill all processes for a specified user
命令:kill -9 $(ps -ef | grep peidalinux)kill -u peidalinux输出:[[email protected] test]# kill -9 $(ps -ef | grep peidalinux) [[email protected] test]# kill -u peidalinux
Method:
Filter out Hnlinux user processes and kill
Instance 6:init process is not to be killed
命令:kill -9 1输出:[[email protected] ~]# ps -ef|grep initroot 1 0 0 Nov02 ? 00:00:00 init [3] root 17563 17534 0 17:37 pts/1 00:00:00 grep init[[email protected] ~]# kill -9 1[[email protected] ~]# kill -HUP 1[[email protected] ~]# ps -ef|grep initroot 1 0 0 Nov02 ? 00:00:00 init [3] root 17565 17534 0 17:38 pts/1 00:00:00 grep init[[email protected] ~]# kill -KILL 1[[email protected] ~]# ps -ef|grep initroot 1 0 0 Nov02 ? 00:00:00 init [3] root 17567 17534 0 17:38 pts/1 00:00:00 grep init
Description
Init is one of the most indispensable programs in Linux system operation. The so-called Init process, it is an internal
A kernel-initiated user-level process. The kernel is self-booting (it has been loaded into memory, started running, and has been initialized
All device drivers and data structures, etc.), by starting a user-level program init
To complete the boot process. As a result, Init is always the first process (its process number is always 1). Other
All processes are child processes of the INIT process, and the INIT process is not to be killed!!!
How to skillfully use KILL command in Linux system, pure Dry goods!!!