Q. How do I kill process in Linux?
A. Linux and all other UNIX like oses comes with kill command. The command kill sends the specified signal (such as kill process) to the specified process or process group. If no signal is specified, the TERM signal is sent.
Kill process using kill command under Linux/UNIX
kill command works under both Linux and UNIX/BSD like operating systems.
Step #1: First, you need to find out process PID (process id)
Use ps command or pidof command to find out process ID (PID). Syntax:
ps aux | grep processname
pidof processname
For example if process name is lighttpd, you can use any one of the following command to obtain process ID:
# ps aux | grep lighttpdOutput:
lighttpd 3486 0.0 0.1 4248 1432 ? S Jul31 0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf lighttpd 3492 0.0 0.5 13752 3936 ? Ss Jul31 0:00 /usr/bin/php5-cg
OR use pidof command which is use to find the process ID of a running program:
# pidof lighttpdOutput:
3486
Step #2: kill process using PID (process id)
Above command tell you PID (3486) of lighttpd process. Now kill process using this PID:
# kill 3486
OR
# kill -9 3486
Where,
- -9 is special Kill signal, which will kill the process.
killall command examples
DO NOT USE killall command on UNIX system (Linux only command). You can also use killall command. The killall command kill processes by name (no need to find PID):
# killall -9 lighttpd
Kill Firefox process:
# killall -9 firefox-bin
As I said earlier killall on UNIX system does something else. It kills all process and not just specific process. Do not use killall on UNIX system (use kill -9).
- Email FAQ to a friend
- Printable version
- Rss Feed
- Last Updated: 08/22/07


{ 18 comments… read them below or add one }
how to kill a process using system call?
Kill are of two types:
1.Graceful Kill
kill -15 pid
2.Forcible Kill
Kill -9 pid.
Kill pid. This format wont work.. Just check it..
These kill differs in releasing resources forcibly or gracefully……….
I login as root, kill -9 a process but it refuses to stop. Is there a more powerful command?
Ganesh
the kill pid works fine if u’re logged in as the root.
I tried to kill a process by kill -9 PID in user as well root mode. But it could not kill the process. What is another way to force kill?
Is the process changing PID after your kill -9 command? Because if it does it means it is a new process. This usually happens with apps that are beeing watched by some other process that will respawn the dead process.
To kill such a process you first need to find out what are the means used to respawn it and act accordingly. A “ps axf” will show you the relationship between processes. If the preocess you try to kill is a child of other process then it is most likely that the parent is respawning the child. So you will need to kill that process first. Otherwise, kill -9 used as root is “invincible” :)
Hi,
One small doubt .
I know parent of all process is init and its PID is zero. Can i kill pid zero? What happend to the system if i kill pid zero?
Regards
Shivin
I have a process that will not respond to any kill signal, nor can bash suspend it, nor did it react on removal of the USB device it was trying to access. I’m told it could be a buggy driver holding a global semaphore or “oopsed”, whatever that is. I guess there are some things that only a reboot will fix. :)
If it is respawning based on an entry in your inittab then you can modify the inittab (eg. remark the entry out) then issue :
/sbin/telinit q
telinit is linked to init and the q flag tells init to re-examine the inittab file.
i have inserted a pendrive in suse linux sp10. when i try to remove the pen drive the dialog displays device busy and shows its process id. every time i use the command kill -9 pid .
how can i avoid this?
Thanks for this tuto, is simple and easy to use
thank you, it works…
Thanks a lot dude!!!
I got a window I cannot close, it is on top and I cannot access to the menus. I cannot move it either, the cursor cannot be moved outseide that window. So the only way to close the application should be a key combination, isn’t it? But which? (BTW, I’m a complete newbie, trying Ubuntu for the first time)
Anybody can guide me how can I kill time based processes? for example I want to kill processes that are 1 day old.
Dear I have a question.
Suppose i have a function that does some calculations.Well what i want to do,I want to stop the calculations in that function after some time (suppose 5 seconds).I really appreciate if anybody guides me in this regard.
thanks in Advance
Very very nice
What is nice ?