How To Terminate A Process In Linux – Kill A Process
In Linux, you can terminate a process from the command line. We going to use three different ways to kill a process running on our test server. The only reason these programs exist is to terminate a process, they have no other useful usage.
Kill, Pkill, Killall
The three functions we are going to use are kill, pkill, and killall and the basic commands for all three are mostly the same;
kill pkill killall
You should always aim to use the kill command first. It’s worth noting that these functions don’t actually kill the process or terminate the process they simply send the kill command to the program or group. If you do not specify a command the default signal, sigterm is sent.
Terminate A Process or Kill A Process
The fact you are looking at how to kill a process in Linux suggests you likely already know what you want to terminate. You can use the top screen or ps -a to list all the processes running on the server. top -c is good if you don’t know the process you want to terminate and you can arrange the active processes by resource usage.
Once you have the PID of the process you want to terminate issue the kill command. First, you will want to send the correct signal. A list of signals can be found on the kill -l page. You can either use the signal name SIGUP or its number 1
kill -SIGUP <PID> pkill -SIGKILL <PID>
Most people use SIGKILL (9) and SIGTERM (15) SIGTERM is the safest way to kill a process on your server. If you are using pkill the signal is the same as kill but for killall the signal names are different.
In cases where you have lots of processes running, it’s very time-consuming typing all the PIDS. You can use killall to terminate all of the processes. It’s much the same as kill or pkill but you use the process name instead of the PID
You can also terminate all processes running under a specific username with killall. I want to terminate all of the processes running under the f2h user so the command would be
killall -u f2h
That’s the basics of kill, pkill, and killall and you now know how to kill a process in Linux. For in-depth information, you can check the man page in Linux from your console. Just issue the man kill, man pkill or man killall command for the full manual.
How was this article?
More from All About Linux
Install Ioncube Loaders In Ubuntu, Debian, CentOS and AlmaLinux
Ioncube Loaders are a piece of software that is used to protect the underlying code in PHP applications. Its aim …
How to install FTP and configure FTP on an Ubuntu 22 LTS instance
If you need to upload files to your NVMe VPS you have a couple of options. You can use a …
How to install a Cloudflare Origin SSL Certificate – NGINX
An SSL Certificate is vital to encrypt data between you and your clients. SSLs can be complicated things. If they …