List of content you will read in this article:
Despite being the most versatile operating system, Linux occasionally experiences application failures that disrupt system operation. These applications become unresponsive to any action. As a result, killing or terminating that running application or process is required to restore the application's proper operation. To resolve this issue, use the kill command in Linux to terminate that process, or you will be aware of the Linux Kill Process.
This article will focus on the kill command and the various options that can be used along with it.
Linux Kill Process [Kill Command in Linux]
The kill command is built-in and available with various shells. The syntax of the command may vary among different shells. To check the kill command’s location on your shell, you can hit the "type" command, as shown below.
type -a kill
Kill Command in Linux with examples
Syntax-
kill [OPTIONS] [PID]...
Where-
- signalNumber: a non-negative decimal integer.
- signalName: it is a symbolic signal name.
- PID: displays the entire list of processes.
To get the list of all the available signals, you can hit the kill command along with the “-l” option, as shown below.
kill -l
You can specify the signals in three different ways as per your requirement-
- number (e.g., -1 or -s 1).
- Along with the “SIG” prefix (e.g., SIGHUP).
- Without the “SIG” prefix (e.g., HUP).
The following commands can be interchangeably used with one another, as they all perform the same action.
kill -1 PID_NUMBER
kill -SIGHUP PID_NUMBER
kill -HUP PID_NUMBER
- PID > 0, this command will send a signal to process with the specified PID.
- PID=0, this command will signal all the processes present within the current process group, i.e., the same GID.
- PID = -1, this command will send the signal to all the processes having the same UID as the user who invokes the kill command. If the specific user is the root user, then the signal will be sent to all processes except the init and the kill process itself.
- PID < -1, this command will send the signal to all the processes available in the process group eq with the GID equal to the PID’s absolute value.
If you are a regular user other than root, you are authorized to send the signal only to their own processes, not even to the processes of another user.
Different values for signalNumber and signalName
Signal Number |
Signal Name (short name) |
0 |
SIGNULL (NULL) |
1 |
SIGHUP (HUP) |
2 |
SIGINT (INT) |
3 |
SIGQUIT (QUIT) |
9 |
SIGKILL (KILL) |
15 |
SIGTERM (TERM) |
24 |
SIGSTOP (STOP) |
25 |
SIGTSTP (STP) |
26 |
SIGCONT (CONT) |
Terminate a process using the kill command
To terminate a process, you can simply use the kill command. But, you need to specify the process ID number (PID) to identify the specific process among all, as each process has a different PID. Follow the commands below listed to accomplish your job.
ps
pid
Now, you have the PID of the “settime” process as “55” that you can specify with the kill command to kill the specific process, as shown below.
kill -9 55
This command will kill the “settime” process.
How to Reload a Process Using the kill Command in Linux
You can also use the kill command to send the required HUP signal, which will help reload the processes' settings.
Another way of using the kill command is to send the HUP signal, which tells the process to reload its settings. In the below example, we have reloaded the process with process id-38 (bioset), as shown below.
Make sure to run the above command with the Sudo privileges.
Conclusion
Whenever a process or application starts malfunctioning or becomes unresponsive to your actions, then you have the leverage to terminate that process manually or forcefully. Linux offers a simple command kill to do that. We have explained how this command works and various options to kill the process in the Linux operating system.
People are also reading:
I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.