Kill process in Linux or terminate a process in UNIX or Linux systems

by Vivek Gite · 35 comments

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:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 35 comments… read them below or add one }

1 kavita 12.19.06 at 8:34 am

how to kill a process using system call?

2 ganesh 10.24.07 at 9:00 am

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……….

3 Josir 11.27.07 at 12:56 pm

I login as root, kill -9 a process but it refuses to stop. Is there a more powerful command?

4 Shehab 02.26.08 at 2:07 pm

Ganesh
the kill pid works fine if u’re logged in as the root.

5 Manojg 06.06.08 at 1:47 pm

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?

6 mircea 06.26.08 at 6:00 pm

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” :)

7 Shivin Vijai 12.03.08 at 9:07 am

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

8 Ethan "eekee" Grammatikidis 01.23.09 at 1:02 am

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. :)

9 Jeff 02.05.09 at 7:12 pm

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.

10 karthickelc 02.19.09 at 12:09 pm

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?

11 Klimentine 04.26.09 at 12:33 pm

Thanks for this tuto, is simple and easy to use

12 maibangcomputer 05.06.09 at 5:34 am

thank you, it works…

13 Sanjay 05.15.09 at 2:25 pm

Thanks a lot dude!!!

14 Shinnosuke 06.26.09 at 10:56 pm

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)

15 sshah 07.07.09 at 8:00 am

Anybody can guide me how can I kill time based processes? for example I want to kill processes that are 1 day old.

16 zaheer arif 08.04.09 at 11:49 am

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

17 vishnu 08.07.09 at 3:57 pm

Very very nice

18 zaheer arif 08.12.09 at 1:36 pm

What is nice ?

19 Natirips 08.20.09 at 5:42 pm

“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.

20 linuxnaveen 08.26.09 at 10:10 am

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

21 linuxnaveen 08.26.09 at 10:33 am

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

22 Ankur Sinha 09.01.09 at 7:28 am

Nice Article!!!!
Thanks!!!

23 kunal 09.10.09 at 9:31 am

how kill command proceed???

24 Raghavi 10.22.09 at 12:37 pm

iam getting this errror plz…. help me

[xsxsx@ip-111-111-11-111 javautils]$ kill 20073
-bash: kill: (20073) – No such process

25 Mircea 10.22.09 at 1:09 pm

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

26 Natirips 10.22.09 at 1:37 pm

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.

27 jw tech 11.09.09 at 7:55 pm

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.

28 SonhadorPR 11.24.09 at 4:33 am

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

29 Natirips 11.24.09 at 5:31 pm

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.

30 Mackie Mathew 12.09.09 at 4:40 am

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

31 Christer Jonassen 01.01.10 at 6:02 pm

Exactly what I needed to kill a troublesome process on my old Clark Connect box!
Thanks!

32 Busandi Lal 01.25.10 at 7:10 am

Hey, you can also use grep command for killing the processes and ls is best known utility for this.

33 Natirips 01.25.10 at 12:31 pm

“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.

34 Michael 01.28.10 at 2:06 pm

What Suse Linux permissions do I need to kill a process?

35 Natirips 01.28.10 at 3:26 pm

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.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All