[Linux] killall, kill, Pkill command detailed

Source: Internet
Author: User
Tags pkill

Killall command

  The Killall command in a Linux system is used to kill a process with the specified name (kill processes by name). We can use the KILL command to kill the process of the specified process PID, if we want to find the process we need to kill, we also need to use the PS and other commands to match grep to find the process, and killall the two processes into one, is a very useful command.

  1. Command format

killall[parameter [process name]

  2. Command parameters

-Z only kills processes that have Scontext-e requires matching process name-I ignores lowercase-G kills Process group instead of process-I interaction mode, asks user-L to list all known signal names before killing process-----Do not output warning message-s sends the specified signal-V to report whether the signal is successfully sent-W wait Process Death--help Display Help information--version display version display

3. Example

1: Kill all the same name process    killall nginx    killall-9 bash2. Send a specified signal to the process    killall-term ngixn  or  killall-kill nginx

KILL command

The KILL command in Linux is used to terminate the run of the specified process (terminate a process) and is a common command for process management under Linux. Typically, terminating a foreground process can use the CTRL + C key, but for a background process to be terminated with the KILL command, we need to use a tool such as ps/pidof/pstree/top to get the process PID, and then use the KILL command to kill the process. The KILL command ends the process by sending a specified signal to the process. By default, a term signal of number 15 is used. The term signal terminates all processes that cannot capture the signal. For those processes that can capture the signal, a kill signal numbered 9 is used to forcibly "kill" the process.

  1. Command format

kill[parameters [process ID]

2. Command parameters

-L signal, if no signal number parameter, then use "-l" parameter will list all the signal name
-A does not restrict the correspondence between the command name and the process number when processing the current process
-p Specifies that the KILL command prints only the process number of the related process without sending any signals
-s specifies the signal to send
-U Specify user

1. Kill command can be with signal number option or without. If there is no signal number, the KILL command emits a stop signal (15), which can be captured by the process, allowing the process to clean up and release resources before exiting. You can also use kill to send a specific signal to the process. For example:
Kill-2 123
#它的效果等同于在前台运行PID为123的进程时按下Ctrl the +c key. However, a normal user can only use a KILL command without the signal parameter or a maximum of 9 signals.

2. Kill can have a process ID number as a parameter. When you send a signal to these processes with kill, you must be the owner of those processes. If you attempt to revoke a process that does not have permission to revoke or undo 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 information is not displayed immediately, only if you press ENTER to make the shell's command prompt reappear.

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 can not return to normal state. Be careful when sending a signal, only use the Kill signal (9) only if it is a last resort, 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, it's a hassle to track down and find the PID of all the processes you want to kill. At this point, it is a valid method to use Kill zero to terminate all processes initiated by the current shell.

2. Example

Example 1: List all signal names
Command: Kill-l
Output:
[Email protected] test6]# kill-l
1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill
5) SIGTRAP 6) SIGABRT 7) Sigbus 8) SIGFPE
9) SIGKILL) SIGUSR1 SIGSEGV) SIGUSR2
Sigpipe) sigalrm SIGTERM) Sigstkflt
SIGCHLD) Sigcont SIGSTOP) SIGTSTP
) (Sigttin) Sigttou () Sigurg) sigxcpu
SIGXFSZ) sigvtalrm sigprof) sigwinch
SIGIO) SIGPWR Sigsys) sigrtmin
(sigrtmin+1) (sigrtmin+2) sigrtmin+3) sigrtmin+4
sigrtmin+5) sigrtmin+6 sigrtmin+7) sigrtmin+8
sigrtmin+9) (sigrtmin+10) sigrtmin+11) sigrtmin+12
sigrtmin+13) (sigrtmin+14) sigrtmin+15) SIGRTMAX-14
SIGRTMAX-13) SIGRTMAX-12-SIGRTMAX-11) SIGRTMAX-10
SIGRTMAX-9) SIGRTMAX-8 () SIGRTMAX-7) SIGRTMAX-6
SIGRTMAX-5) SIGRTMAX-4 () SIGRTMAX-3) SIGRTMAX-2
SIGRTMAX-1) Sigrtmax

Description
Only the 9th signal (SIGKILL) can terminate the process unconditionally, other signal processes have the right to ignore. The following are commonly used signals:
HUP 1 terminal disconnection
INT 2 Interrupt (with Ctrl + C)
Quit 3 exit (with Ctrl + \)
Term 15 termination
Kill 9 Forced termination
CONT 18 Continuation (contrary to stop, FG/BG command)
Stop 19 paused (with Ctrl + Z)


Example 2: Get the value of the specified signal

[[email protected] test6]# kill-l Kill
9
[Email protected] test6]# kill-l SIGKILL
9
[Email protected] test6]# kill-l term
15
[Email protected] test6]# kill-l SIGTERM
15
[Email protected] test6]#


Example 3: First use PS to find the process, then kill with Kill

Command: Kill 3268
[Email protected] test6]# Ps-ef|grep vim
Root 3268 2884 0 16:21 pts/1 00:00:00 vim Install.log
Root 3370 2822 0 16:21 pts/0 00:00:00 grep vim
[[email protected] test6]# kill 3268


Example 4: Kill the process completely
Command: kill–9 3268//-9 Force Kill process


Ps:init is one of the most indispensable programs in Linux system operation. The so-called Init process, which is a user-level process initiated by the kernel. After the kernel has booted itself (already loaded into memory, started running, and has initialized all device drivers and data structures, etc.), the boot process is completed by starting a user-level program init. As a result, Init is always the first process (its process number is always 1). All other processes are descendants of the INIT process. The init process is not to be killed!

PKILL

Pkill and Killall Apply the same method, but also directly kill the running program, if you want to kill a single process, please kill with kill.
Application method: #pkill The Running program name

[Linux] killall, kill, Pkill command detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.