Process management is one of the important aspects of System Administration in Linux, and it includes killing of processes using the kill command.
In this how-to, we shall look at killing of less productive or unwanted processes on your Linux system.
What is a Process in Linux?
A process on a Linux system can be a running occurrence of an application or program. You can also refer to processes as tasks executing in the operating system.
When a process is running, it keeps on shifting from one state to another and a process can in one of the following states:
- Running: meaning the process is either executing or it is just set to be executed.
- Waiting: meaning that the process is waiting for an event or for a system resource to carry out a task.
There are two types of waiting process under Linux namely interruptible and uninterruptible.
A waiting process that can be interrupted by signals is called Interruptible, while a waiting process that is directly waiting on hardware conditions and cannot be interrupted under any conditions is called uninterruptible.
- Stopped: meaning that the process has been stopped, using a signal.
- Zombie: meaning the process has been stopped abruptly and is dead.
With this brief overview let us now look at ways of killing processes in a Linux system. We’ve already covered a few articles on ways to kill Linux running processes us using kill, pkill, killall and xkill, you can read them below.
- A Guide to Manage Linux Processes Using Kill, Pkill and Killall Commands
- How to Kill Unresponsive Linux Processes Using Xkill Command
When killing processes, the kill command is used to send a named signal to a named process or groups of processes. The default signal is the TERM signal.
Remember that the kill command can be a built-in function in many modern shells or external located at /bin/kill.
How to Find Process PID in Linux
In Linux every process on a system has a PID (Process Identification Number) which can be used to kill the process.
You can identify the PID of any process by using the pidof command as follows:
$ pidof firefox $ pidof chrome $ pidof gimp-2.8
How to Kill Processes in Linux
Once you find the process PID, let us now look at how to kill processes. In this first example, I am going to first get the PID of the process and then send a signal to it.
I want to kill gimp process, so I will do it as follows:
$ pidof gimp-2.8 $ kill 9378
To verify that the process has been killed, run the pidof command and you will not be able to view the PID.
$ pidof gimp-2.8
You can also send a named signal to the process by using the signal name or numbers as follows:
$ pidof vlc $ kill -SIGTERM 9541 $ pidof vlc
Using the signal number to kill a process:
$ pidof banshee $ kill -9 9647 $ pidof banshee
In the above example, the number 9
is the signal number for the SIGKILL signal.
How to Kill Multiple Process PID’s in Linux
To kill more than one process, pass the PID(s) to the kill command as follows:
$ pidof gimp-2.8 $ pidof vlc $ pidof banshee $ kill -9 9734 9747 9762
Summary
There are many other ways of killing processes in Linux, these few examples just help to give you an overview of killing processes. Do let us know how you kill processes in Linux? and also tell other ways if any via comments.
How to find out the most CPU utilizing process and kill the process.
Thank you Aaron . Nice simple article. gj!
@Jan
Welcome, many thanks for appreciating our work, and the useful feedback.
sudo Kill -15 [pid]
The best of all to kill a process in Linux
Easier way is to use pkill appname
Hi! :-)
“killall” is a better options than “kill” at my opinion.
Also a usefull diagnose tool if a program crashes, is the “htop”.
In case of such a problem, I’m switching to another virtual console (eg. with Ctrl-Alt-F1) and I’m giving “htop” (after logging in), in order to find out wich process is the problematic one.
After that I can kill it from inside “htop”, or exit from it and use “killall”.
Just my 2 cents.
Bye! :-)
G.
pkill is even better. With killall you might select more process than what you want, pkill allow you to select more precisely :)
Getting the right utility to use is very important for a given situation when killing processes. It is good to know when to use kill, killall, pkill and pgrep.
Hi Aaron can you tell me what you use to make that GIF animation i mean the tool you use to create it
@Roy,
We use Simple Screen Recorder tool to create such beautiful animated GIF’s, you can learn more about it at:
https://www.tecmint.com/screencasting-with-simple-screen-recorder-in-linux/