Today I will be showing you how to kill Linux processes. There are a few ways to accomplish this and I will be highlighting them all below. If I miss anything then feel free to comment below and I will add the information to this post as-well.
Killing A Specific Process
The easiest way for you to kill a specific process is to find the PID (process ID) and then use the kill command. Here is an example of doing so.
pidof firefox kill 5651
Alternatively if you need to find the PID of a process you can use the ps command to find it.
ps aux | grep "processname"
Killing Multiple Processes
If you need to kill multiple processes for example multiple instances of Firefox on a Linux desktop, you can use the killall command. You will not need to specify a PID. Using killall will do what the name states though, it will kill all instances so if you would like to for example keep one instance of Firefox open then don’t use this.
Killing Zombie Processes
So the heading for this section is somewhat misleading. You can’t actually kill a zombie process directly, to kill a zombie process (z state processes) you have to kill its parent process. For example if you have a script that creates a sub process and that sub process becomes a zombie, you can only kill it by killing the script that created it (or rebooting).
Here are the steps to killing a zombie process (or at-least attempting to). First we will need the PID (process ID) of the zombie process we intend to kill.
pidof <process name>
Next we need the parent process ID (PPID). You can find this out with a number of different ways, the quickest and easiest way is to run the following command. Note: replace <process ID> with the process ID.
ps -o ppid= -p <process ID>
Next you will need to kill the parent process, you can do this with the kill command.
kill <parent process ID>
Thank you for reading, please don’t forget to like, comment, or share to support the blog! If you are looking for more information on killing processes, then I would highly recommend this useful post.