End a process using the KILL command in Linux

Home > Search > Linux commands
  by

The kill command can be used to end a process. For example, let's say the gedit program is using process ID (PID) 16674. The kill command followed by 16674 will end the gedit process.

[john.doe@server1 ~]# kill 16674

 

The kill command can use the PID or Job ID number of the process to end. However, the kill command cannot accept the name of the process. For example, kill gedit cannot be used to end the gedit process. Instead, the killall command can be used to end a process using the process name.

 


SIGNALS

The kill command can use different signals. A signals represents how a process should be ended. For example, the terminate signal is less aggresive than the quit signal. Following are some of the common signals.

Signal Number Name
Hangup 1 sighup
Interupt 2 sigint
Quit 3 sigquit
Kill 9 sigkill
Terminate 15 sigterm

 

When a certain signal is not specified, the terminate signal is used. 

The kill command followed by the signal name or signal number can be used to end a process with a particular signal. In this example, the hangup signal is used.

[john.doe@server1 ~]# kill -1 16674

 

In this example, the quit signal is used.

[john.doe@server1 ~]# kill -sigquit 16674

 


WORKING EXAMPLE

Let's take an example where gedit is opened in the foreground, and then Ctrl + Z is issued in the Terminal to stop gedit. Gedit remains open, and the kill command with the default terminate signal fails to end gedit.

 

In this scenario, using a different kill signal should end gedit. The kill signal (9) is able to end gedit.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments