The University of Queensland Homepage
School of ITEE ITEE Main Website

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

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

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!

{ 18 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 ?

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 post: How reduce or shrink Logical Volume on Linux

Next post: Why my Apache Server Side Include (SSI) is not working?