How to Kill Process in Linux

How to Kill Process in Linux
How to Kill Process in Linux

Kill Process in Linux

Whenever an application becomes unresponsive and gets crashed unexpectedly. If you are trying to start that application again then it won’t start because application process not completely closed at such time you should kill the application process. Then the application will start again easily. In this tutorial, we are going to learn how to kill the process in Linux by using kill and killall commands.

Basic Syntax For kill and killall

Both kill and killall commands are used to terminate the processes. The main difference is that kill command terminates the process with process id while killall command terminates the process with process name.

The basic syntax for kill command is given below:

kill [SIGNAL] pid

SIGNAL: the following signals will be sent to the processes after executing the command. While you can check all the signals running
kill -l command.

  • -HUP (1): restart the process
  • -KILL (9): kill the process
  • -TERM (15): gracefully stop the process (the default signal)

The basic Syntax for killall command is given below:

killall [ -Z CONTEXT ] [ -u USER ] [ -y TIME ] [ -o TIME ] [ -eIgiqrvw ] 
[ -s SIGNAL | -SIGNAL ] NAME

where excluding NAME all other arguments are optional

  • -Z CONTEXT: kill the only process(es) having context (must precede other arguments
  • -u USER: kill only process(es) running as USER
  • -y TIME: kill processes younger than TIME
  • -o TIME: kill processes older than TIME
  • -eIgiqrvw : These are the group of commands.
  • -s SIGNAL: send this signal instead of SIGTERM

How to kill process with kill command

kill command is used to terminate the process with process id called PID. To get PID of a process you can use commands like pidof, ps etc. Then by using PID of a process, you can kill the processes.

For example, if you want to get the process id of vlc media player then you can run the following command.

pidof vlc

The output should look like:

7223

Now terminate vlc process using the killcommand.

kill 7223

Similarly, if you want to check process id for Google Chrome the run following command.

pidof chrome

You will get output like following

6470 6455 6324 6283 6269 6255 6224 6191 6171 6038 6009 5996 5995 5994 5985 5984 5979 5971 5964 5959 5944 5799 5667 5642 5640 5528

To terminate all of above process run below command:

kill -9 6470 6455 6324 6283 6269 6255 6224 6191 6171 6038 6009 5996 5995 5994 5985 5984 5979 5971 5964 5959 5944 5799 5667 5642 5640 5528

How to kill the process with killall command

killall terminates all the processes that match with the given name. You can kill the processes without getting process id.

Now to kill the process vlc typing following command and hit ENTER in terminal:

killall vlc

Similarly to kill Google chrome process run below command:

killall chrome

Conclusion

You have successfully learned how to kill process in Linux. If you have any queries regarding this then please don’t forget to comment below.