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).
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- My 10 UNIX Command Line Mistakes
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email FAQ to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: 08/22/07



{ 38 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 ?
“nice” is how nice a process is. The higher the number, it will tend to let other processes use CPU more. If negative, it has higher priority that other processes. Zero (0) is normal. See “man renice” to see how to change the “nice” value.
Dear Shivin,
The Init is the parent of all the process.The PID no is always One (1).
It’s an Parent of all the process so we called PPID.
All the runlevels are run under init.So it’s look like parent of all the runlevels.
If you kill the init ,then how it works…?
Thanks & Regards,
EverFriendly Naveen
Dear Shivin,
The root PID is zero (0)
Run this command it will show
pidof root
pidof init
The root is an User.The User informtions are stored in /etc/passwd file
in this file show
username,password,userid,groupid,gecos field,home directory,shelltype
The third field denotes the UID of the User.
Thanks & Regards,
Ever Friendly Naveen
Nice Article!!!!
Thanks!!!
how kill command proceed???
iam getting this errror plz…. help me
[xsxsx@ip-111-111-11-111 javautils]$ kill 20073
-bash: kill: (20073) – No such process
This usually means exactly what the message says: there is no process with that id running. This may be due to short lived processes or simply a typo in the command line
If you’re shore that you’ve seen a process with that PID, it may have died/ended on it’s own before you could type the command. You can check if a process is alive with “ps -e” (without the quotes) and looking at the list, or just “ps -e|grep 12345″ to see if a process with PID 12345 exists or not. Note that every time you start an application, it will get a different PID. So if you killed a broken MPlayer or VLC (for example), when you start it again it will have another PID. If you start two instances of it, each will have it’s own PID. Also, the same PID my accidentally later be given to a completely different application. So never remember PID of given process by long term means.
I am using the
sudo killall -u root
as root but once all the machines have been killed the command will not end/terminate I have to go in and click the stop button.
Following a few of the commands, the kill -9 or kill -15 PID did not work for me, because it kept changing, like mircea had mentioned, it apparently was attached to another process. However, nobody told me how to find the other process…so I used the sudo killall -u root, mentioned by jw tech, and all it did was log me out of my session, however, for some reason it also killed the USB, because the mouse and keyboard did not respond.
Had to manually turn machine off…waste of time, I could have turned off machine from beginning!
Any other step-by-step commands for newbies like me?
Let meknow: sonhadorpr_at_gmail_dot_com
killall -u root is only usefull if you’re trying to shutdown the machine “gently” as it kills everything it can.
Use “$ ps -ejH” to display all processes in a tree. You might want to also “$ ps -ejH>tempprocesseslist;gedit tempprocesseslist;rm tempprocesseslist” to view the files nicely. Use ‘kate’, ‘mousepad’, ‘vi’, ‘nano’ or whatever instead of ‘gedit’ if you like/need.
Btw, don’t type/copy-paste the quotes and the $ sign ^^.
Now if you’re killing a process but it jumps back, maybe try killing/debugging it’s parent instead. Parent processes are those to the left (with less spacing at the left side) in the “tree”.
Explanation:
‘$ ps -ejH’
Displays all processes in a tree. This part is almost absolutely harmless (it takes up a lot of screen space). Use shift+pageUp/pageDown to scroll through the list if you’re stuck in CTRL+ALF+F1-6.
‘$ ps -ejH>tempprocesseslist’
Outputs to a file named ‘tempprocesseslist’ instead of screen. You can use any other filename istead of ‘tempprocesseslist’, but than you must use the same one in all three commands.
‘$ ps -ejH>tempprocesseslist;gedit tempprocesseslist’
Also open the file in text editor.
‘$ ps -ejH>tempprocesseslist;gedit tempprocesseslist;rm tempprocesseslist’
Also remove the file after it is no longer needed.
I like to get a tree view before killing off a process. Graphics make me happy :) and also useful when the process table is a bit too complex to grasp.
If I want to kill firefox (No offence mozilla ;), this is what I use:
pstree -p | grep fire*
this displays:
|-firefox(28060)-+-{firefox}(28070)
| |-{firefox}(28071)
| |-{firefox}(28072)
Then I would kill it using:
kill -9 28060
Exactly what I needed to kill a troublesome process on my old Clark Connect box!
Thanks!
Hey, you can also use grep command for killing the processes and ls is best known utility for this.
“grep” doesn’t kill a process, it is only used to filter output of other commands such as “ps” or “pstree”, at least in this context.
“ls” has practically absolutely nothing to do with killing a process. It is used to list segments (usually files) in a directory.
What Suse Linux permissions do I need to kill a process?
I’m not 100% sure as I’m not a Suse user, but this should do if you don’t have permissions to kill it:
$ su
Password:
# ps -e|grep part-of-process-name
# kill -9 PID
# exit
$ echo continue with what you were doing
Where PID is process ID (that number). You can use ‘pstree’ instead of ‘ps -e|grep blah’ if you want.
how can i kill safari?
OK. Here’s step-by-step how to kill anything.
Open a terminal (Konsole, Terminal, xterm, gnome-terminal, or press CTRL+ALT+F1*). Don’t type in the $ and # signs. Those indicate the beginning of a line which you have to type. *You can use any key from F1 to F6 here. Press CTRL+ALT+F7 to go back to the GUI.
Type:
$ ps -e
If you don’t see the whole list, you can scroll up and down with SHIFT+PAGE_UP and SHIFT+PAGE_DOWN.
Find the process’ number and type:
$ kill 12345
Where 12345 is the number of your process.
If it didn’t die, type:
$ kill -9 12345
Where 12345 is the process’ number.
If it still didn’t die, type:
$ su
# kill -9 12345
# exit
You can also use:
$ sudo su
instead of “$ su” if you don’t know/have the root password but you happen to be a sudo-er.
If it still didn’t die, type:
$ pstree
Now find process’ parent process (the one to the left of it), and repeat everything for the parent process.
Warning: don’t try killing “gdm”, “kdm”, “xdm” or “init” unless you really know what you’re doing.
You can also use:
$ pkill fullprocessname
instead of
$ kill processnumber
You can usually see the full process’ name in the “pstree” and “ps -e”, next to it’s number.
If you want to kill all instances of something, type:
$ killall fullprocessname
Full process name may be different from the program’s name, for example firefox’s full process name may be “firefox-bin” instead of just “firefox”.
Both pkill and killall can use -9 parameter as well. This parameter tells it to kill forcefully (and not gently). For example:
$ pkill -9 firefox-bin
$ killall -9 npviewer.bin
many thanks
do you know how can i remove an application using unix command?