How to force kill process in Linux using kill and killall

last updated in Categories , , , ,

I am a new Linux system administrator. How can I force kill process in Linux?

You need to use the kill 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

  1. Use pidof command to find the process ID of a running program or app
    pidoff appname
  2. To kill process in Linux with PID:
    kill -9 pid
  3. To kill process in Linux with application name:
    killall -9 appname

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 to kill on Linux
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:
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
Force kill process in Linux using killall command

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. The units are:

UnitMeaning
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

Conclusion

This page showed how to use the kill and killall commands on Linux operating systems to terminate processes forcefully.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive

1 comment

    Still, have a question? Get help on our forum!