Unix and Linux like operating systems processes uses SIGNALS in order to communicate each other. For example If we can to kill a process we need to send a signal to process we want to kill. This signal will be SIGTERM and send by kill
or similar commands. In this tutorial we will examine the SIGTERM signal and compare with SIGKILL signal.
Linux Kill Process Tutorial With Examples
SIGTERM
The SIGTERM signal is a generic signal used to terminate a program. SIGTERM provides an elegance way to kill program. This is useful because SIGTERM can be handled with different ways like block, ignore etc. This is the polite way to kill application or program. The default behavior of the kill command is sending SIGTERM signal to a process.
Send SIGTERM Signal To A process
As stated previously we can send SIGTERM signal to a process by simply using kill
command with the Process ID or simply PID. First we need to get the process ID with pgrep command like below. In this example we want to kill Firefox process.
$ pgrep firefox
AND we will use kill
command default behaivour with the process ID which is 2229 in this case.
$ kill 2229
Send SIGTERM Signal Root or Other Users Processes
In some cases we may need to send SIGTERM signal to the root
or other users processes. We can use sudo
command in other to get root
privileges which will give us power to kill all processes in the Linux system.
$ sudo kill 2229
SIGTERM vs SIGKILL
SIGTERM and SIGKILL provides similar functionalities. Both kill given process or program. But there are some minor diffirencies.
- SIGTERM try to kill politely on the other side SIGKILL will kill in harsh way
- SIGTERM can be handled but SIGKILL can not be handled
- SIGTERM is the first way to kill a process but it do not work SIGKILL can be used.
Send SIGKILL Signal To A Process
If SIGTERM do not works as we expect we can use the harsh way which is SIGKILL . We can send SIGKILL signal with kill
command with -9
option which specifies SIGKILL signal.
$ kill -9 2220