Skip to main content

Command Palette

Search for a command to run...

Various ways of process termination

Published
3 min read
Various ways of process termination
M

Hi, How are you !! Hope you doing good....

I got introduced to Cloud initially. As I went ahead learning what is cloud and how it works, then got to know a field which is DevOps that makes Cloud model more effective.

So, as I started working & got good experience on AWS. I have been learning the DevOps tool and technologies on how to use it with the Cloud, which will give me good understanding on how Cloud and DevOps go hand in hand to deploy my applications.

Last Blog Review

In the last blog we understood, multiple process states, what it means to terminate a process. KILL command and how to use a KILL command to terminate a process.

Other ways to terminate a process

  1. killall command

    In kill command we saw that we can terminate a process using PID rather than the process name. But its difficult to remember the PID, instead we can remember the process name very easily.

    The killall command makes it easier to kill a process since it takes the command name as a parameter to kill a process.

    Syntax of the killall command:

killall process_name AND killall -signal process_name

For example, we can kill the google process by name, as follows:

$ killall google # google application gets terminate
  1. pkill command

The pkill command also kills a process by its name. Unlike the killall command, by default the pkill command finds all the processes beginning with the name specified in its argument.

For example, the following command demonstrates how pkill kills the firefox process from its partial name specified in an argument:

$ pkill firef # Kills processes beginning with name firef and hence firefox

Concern with pkill cmd - It has to be handled carefully, as it will kill all the matching processes.

2.1

pgrep -l → We can determine which process are going to be killed by pkill command using pgrep and listing it using -l

If we run below command, then it will list all the matching process and there PID

$ pgrep fire
    747 firewalld
    8168 firefox

So, in such cases we can tell the pkill command to kill a process with exact match of process name using the --exact or -x flag.

 $ pgrep -x -l  firef  # No match found
 $ pkill -x fire  # Nothing gets killed
 $ pgrep --exact -l firefox   # Process firefox found
 1000 firefox
 $ pkill --exact firefox  # Process firefox will be killed

Difference between kill, killall, pkill

  1. kill → Can be used to kill the process using it’s PID

  2. killall → Can be used to kill the process using the process name

  3. pkill → Can be used to kill all the matching process which we dont want at once.

Conclusion →

In this blog we understood, killall command, pkill command and the difference between kill, killall, pkill command to terminate a process.

💡
That’s a wrap for today’s post! I hope this has given you some valuable insights. Be sure to explore more articles on our blog for further tips and advice. See you in the next post!

More from this blog

Mihir's Tech blog

69 posts