Iam a new Linux system administrator. How can I force kill process in Linux?
You need to use the kill command or killall command on Linux operating systems to terminate processes without having to log out or restart the server. This page shows you how to force kill process in Linux.
How to force kill process in Linux
- Use the pidof command to find the process ID of a running program or app
pidof appname - To kill process in Linux with PID immediately:
kill -9 pid - Want to kill process in Linux with application name forcefully? Try:
killall -9 appname - You can sent -15 (SIGTERM) signal to process requesting it to terminate gracefully:
killall -15 your-app-name
AND
kill -15 pid
SIGTERM (-15) vs SIGKILL (-9) signals
SIGTERM (-15) vs SIGKILL (-9) re signals in Linux, macOS, FreeBSD/OpenBSD/NetBSD and Unix-like systems to terminate processes.
SIGTERM | SIGKILL |
---|---|
You send a SIGTERM signal when you wish to terminate a process gracefully. Gracefully means the process will try to save data, close log files if any open and do a clean shutdown. | You send a SIGKILL signal when you wish to terminate a process forcefully and immediately. This operation is messy, and data may be saved and have an unexpected outcome. Hence, it should be used as a last resort. |
When a Linux/Unix process or PID receives a SIGTERM signal, it can catch the signal and handle it in a custom way. For example, it can simply terminate itself or save data and then terminate. It is the safest option. | When a Linux/Unix process receives a SIGKILL signal, it cannot catch it. Hence, the process cannot perform cleanup actions or save the data. Instead, it is forcefully terminated immediately. |
If the process does not terminate with SIGTERM and after a reasonable time, then ONLY you send a SIGKILL signal to force termination. | Hence, as a developer or sysadmin, you use SIGKILL as a last resort when a process is not responding to other signals or when the process is causing problems that need to be resolved immediately to stabilize your Linux or Unix system. |
The syntax is: kill -15 pid killall -15 app-name sudo kill -15 pid sudo killall -15 app-name | The syntax is: kill -9 pid killall -9 app-name sudo kill -9 pid sudo killall -9 app-name |
Only the root user can kill the system level and other users process with either SIGKILL or SIGTERM. You can send SIGKILL or SIGTERM signals to your process only. |
How to Kill a Process in Linux
Let us try to kill a process that is called firefox. To find firefox pid run any one of the following commands:pidof firefox
pgrep firefox
ps aux | grep firefox

Locating the process (PID) to kill on Linux
Each process is automatically assigned a unique process identification number (PID) in Linux. In this example it is 27707.
Force kill process on Linux command line
To kill process on Linux use the kill command:kill pid
kill -SIGKILL pid
kill 27707
By default signal 15, named SIGTERM, is sent to kill process. Hence all of the following are doing same things:kill -15 27707
kill -SIGTERM 27707
kill 27707
Verify that firefox process gone using the pidof/pgrep command or combination of the ps command and grep command to locate running Linux process. For instance:pidof firefox
pgrep firefox
ps aux | grep firefox
There are many signals that can be used with kill, but, most users will only need to be aware of signal 9 and 15. To get full list, run:kill -l
Sample outputs:
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
How to Kill a Process in Linux using SIGKILL
Sometime -SIGTERM (-15) fails, the stronger signal 9, called SIGKILL, should be used for force killing of process. For example, the following command would guarantee that process 27707 would be killed:kill -9 27707
kill -SIGKILL 27707
Linux force kill process using killall command

Instead of using PID one can kill any process by name using the killall or pkill command. The syntax is:killall -9 app
pkill -9 app
The killall command sends a signal to all processes running any of the specified commands. For example, forcefully kill all nginx process, run:killall -9 nginx
You may want to run the killall command as root user to kill process of all users on Linux:sudo killall -9 nginx
It is also possible to kill process with confirmation:killall -9 vim
How to kill processes older than TIME
Want to kill a process called vim that has been running for more than 24 hours? Try:killall -o 24h appName
killall -o 24h vim
The time is specified as a float then a unit.
Meaning | Unit |
---|---|
s | seconds |
m | minutes |
h | hours |
d | days |
w | weeks |
M | Months |
y | years |
How to kill processes younger than TIME
Let us kill a process that has been running for less than 60 minutes:killall -y 60 -9 appName
killall -y 60 -9 firefox
How to kill only process(es) running as USER
Say you want to kill vim process that in running as vivek user, run:killall -u {user} -9 vim
killall -u vim -9 vim
A note about SIGHUP (-1) signal
You may see some examples of SIGHUP (-1) signal. For example:sudo kill -1 pid
sudo kill -HUP $(cat /var/run/SERVICE.pid)
The SIGHUP (HUP or -1) signal informs a process that its controlling terminal has been disconnected. However, depending on the context, the process can catch the signal and do custom stuff. Here are some examples where you may wish to send SIGHUP instead of SIGTERM or SIGKILL:
- Say you want to reload a system service. For example, reload sshd service after you update a configuration file and to load new changes without killing the sshd service. So you write:
sudo kill -1 $(cat /var/run/sshd.pid)
## OR ##
sudo kill -SIGHUP $(cat /var/run/sshd.pid)
In the system log file, you will see the following entry immediately. For instance, we can see /var/log/auth.log under a Debian/Ubuntu Linux using the grep command or tail command:tail -f /var/log/auth.log
tail -f /var/log/auth.log | grep -i SIGHUP
Outputs:Mar 25 13:56:37 wks01 sshd[1555]: Received SIGHUP; restarting. Mar 25 13:56:37 wks01 sshd[1555]: Server listening on 0.0.0.0 port 22. Mar 25 13:56:37 wks01 sshd[1555]: Server listening on :: port 22. - Some processes can interrupt a running process and force it to dump its current state for debugging purposes when they get SIGHUP.
- We can also send SIGHUP to a remote process to notify it that the network connection is closed or lost.
- Another usage is to send SIGHUP to all processes in a process group to notify them of a change. For example, Nginx or PHP-FPM process works in parent/child or primary/secondary model. So you can terminate the parent or primary process with SIGHUP.
- In short, SIGHUP is a signal that can be used to notify a Linux/Unix process of a significant event or change, such as you made changes to a configuration file. Some services handle SIGHUP, and others ignore it. Hence, it all depends upon context; therefore, you need to process the documentation to see how they handle the SIGHUP.
Conclusion
This page showed how to use the kill and killall commands on Linux operating systems to terminate processes forcefully. As explained in Table 1, SIGTERM is a gentler way to ask a process to terminate, while SIGKILL is a more forceful way to terminate a process that is not responding to other signals. Therefore, try SIGTERM first, and only last resort to SIGKILL if necessary. The kill/killall commands has many more options. Hence, read the manual page using the help command or man command as follows using the Linux terminal session:man kill
man killall
man ps
man pgrep
Vivek Gite is an expert IT Consultant with over 25 years of experience, specializing in Linux and open source solutions. He writes about Linux, macOS, Unix, IT, programming, infosec, and open source. Follow his work via RSS feed or email newsletter.
Author: Vivek Gite Last updated: April 24, 2024 6 comments