English
+370 5 205 5502 sales@monovm.com

How to use the kill command?

This article will focus on the “kill” command and various options that can be used along with this command.

18 Feb, 22 by Susith Nonis 4 min Read

List of content you will read in this article:

Despite being the most versatile operating system, Linux sometimes faces the malfunction of some applications that impact the system’s working. These applications become unresponsive to any action. Thus, it becomes necessary to kill or end that running application or process to restore the proper working of the application. To solve this purpose, Linux provides the “kill” command.

This article will focus on the “kill” command and various options that can be used along with this command.

The “kill” command is shell builtin 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

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.

For getting 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 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 specified PID.
  • PID=0, this command will signal all the processes present within the current process group, i.e., 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 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)

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.

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. 

You can also use the ‘kill” command for sending the required HUP signal that will help in reloading the settings of the processes. 

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.

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 along with various options. 

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I veture into the world of Technology I try to share what I know in the simplest way possible. Not a fan of coffee, a sweet addict and a self accredited 'master chef'.