Posted on March 9, 2023 by darshin
There are several utilities that allow you to terminate errant processes with
kill the being the most commonly used.
kill is a shell builtin in most Bourne-derived shells such as Bash and Zsh. The command behavior is slightly different between the shells and the standalone
type command to display all locations on your system containing
type -a kill
kill is a shell builtin kill is /usr/bin/kill
The output above tells that the shell builtin has priority over the standalone executable, and it is used whenever you type
kill. If you want to use the binary, type the full path to the file
/bin/kill. In this article, we will use the Bash builtin.
The syntax of the
kill command takes the following form:
kill [OPTIONS] [PID]...
kill command sends a signal to specified processes or process groups, causing them to act according to the signal. When the signal is not specified, it defaults to
The most commonly used signals are:
HUP) – Reload a process.
KILL) – Kill a process.
TERM) – Gracefully stop a process.
To get a list of all available signals, invoke the command with the
Signals can be specified in three different ways:
Using number (e.g.,
Using the “SIG” prefix (e.g.,
Without the “SIG” prefix (e.g.,
The following commands are equivalent to one another:
kill -1 PID_NUMBERkill -SIGHUP PID_NUMBERkill -HUP PID_NUMBER
The PIDs provided to the
kill command can be one of the following:
PIDis greater than zero, the signal is sent to the process with ID equal to the
PIDis equal to zero, the signal is sent to all processes in the current process group. In other words, the signal is sent to all processes belonging to the GID of the shell that invoked the
ps -efjcommand to view the process group IDs (GIDs).
PIDis equal to
-1, the signal is sent to all processes with the same UID as the user invoking the command. If the invoking user is root, the signal is sent to all processes except init and the
PIDis less than
-1, the signal is sent to all processes in the process group eq with GID equal to the absolute value of the
Regular users can send signals to their own processes, but not those that belong to other users, while the root user can send signals to other user’s processes.
Terminating Processes Using the
To terminate or kill a process with the
kill command, first you need to find the process ID number (PID). You can do this using different commands such as
Let’s say the Firefox browser has become unresponsive, and you need to kill the Firefox process. To find the browser PIDs use the
The command will print the IDs of all Firefox processes:
971 970 969 968 967 966 965 964 963
Once you know the processes numbers, you can kill all of them by sending the
kill -9 6263 6199 6142 6076
Instead of searching for PIDs and then killing the processes, you can combine the above commands into one:
kill -9 $(pidof nginx)
Reloading Processes Using the
Another common use case for
kill is to send the
HUP signal, which tells the processes to reload its settings.
For example, to reload Nginx , you need to send a signal to the master process. The process ID of the Nginx master process can be found in the
nginx.pid file, which is typically is located in the
cat command to find the master PID:
Once you found the master PID reload the Nginx settings by typing:
sudo kill -1 30251
The command above must be run as root or user with sudo privileges.
kill command is used to send a signal to processes. The most frequently-used signal is
-9, which terminates the given processes.
Leave A Comment
What’s happening in your mind about this post !
How to use the nohup command in linux - Nexonhost.com (May 4, 2023)
[…] for some reason you want to terminate the process, use the kill command followed by the process […]