Kill Process in Linux or TerminUe A Process in UNIX
Kill Process in Linux or TerminUe A Process in UNIX
I
am a new Linux system user. How do I kill process on Linux based server using
command line options? How can I kill running process on Unix?
Linux and Unix-like operating system come with the kill command to terminates stalled
or unwanted processes without having to log out or restart the server.
The kill command sends the specied signal such as kill process to the specied process or process groups. If
no signal is specied, the TERM signal is sent. Please note that kill command can be internal as part of modern
shells built-in function or external located at /bin/kill. Usage and syntax remain similar regardless internal or
external kill command.
Linux and Unix-like operating system supports the standard terminate signals listed below:
1. SIGHUP (1) Hangup detected on controlling terminal or death of controlling process. Use SIGHUP to
reload conguration les and open/close log les.
2. SIGKILL (9) Kill signal. Use SIGKILL as a last resort to kill process. This will not save data or cleaning kill
the process.
3. SIGTERM (15) Termination signal. This is the default and safest way to kill process.
What is a PID?
A Linux or Unix process is running instance of a program. For example, Firefox is a running process if you are
browsing the Internet. Each time you start Firefox browser, the system is automatically assigned a unique
process identication number (PID). A PID is automatically assigned to each process when it is created on the
system. To nd out PID of refox or httpd process use the following command:
pidof httpd
pidof apache2
pidof firefox
ps aux
|
grep httpd
ps aux
|
grep apache2
Sample outputs:
Fig.01: Find the process ID (PID) of a running refox program and apache2 server.
Use the ps or pidof command to nd out PID for any program. For example, if process name is lighttpd, you
can use any one of the following command to obtain process ID:
pidof lighttpd
Sample outputs:
3486
OR
Sample outputs:
The PID # 3486 is assigned to the lighttpd process. To kill the lighttpd server, you need to pass a PID as follows:
# kill 3486
OR
H O W D O I V E R I F Y T H AT T H E P R O C E S S I S G O N E / K I L L E D ?
If no signal specied in the kill command, signal # 15 (SIGTERM), is sent by default. So the kill 3486
command is same as the following command:
Sometime signal # 15 is not sufcient. For example, lighttpd may not be killed by signal #15 due to open
sockets. In that case process (PID) # 3486 would be killed with the powerful signal # 9:
# kill -9 3486
# kill -SIGKILL 3486
OR
Where,
-9 or -SIGKILL A special kill signal that nearly guarantee to kill the process with the iron st.
The syntax is as follows to kill two or more PIDs as required can be used in a single command:
This is a Linux only command. to kill processes by name. So no need to nd the PIDs using the pidof process
or ps aux | grep process command. Do not use killall command on Unix operating systems. This is a Linux
specic command.
The syntax is
killall Process-Name-Here
OR
# killall -9 lighttpd
# killall -9 firefox-bin
As I said earlier, the killall command on UNIX-like system does something else. It kills all process and not just
specic process. Do not use killall on UNIX system.