Kill Process in Linux or Terminate a Process in UNIX / Linux Systems

Posted on in Categories , , last updated December 31, 2014

I am a new Linux system user. How do I kill process on Linux based server using command line options? How can I kill running process on Unix?

Linux and Unix-like operating system come with the kill command to terminates stalled or unwanted processes without having to log out or restart the server.

The kill command sends the specified signal such as kill process to the specified process or process groups. If no signal is specified, the TERM signal is sent. Please note that kill command can be internal as part of modern shells built-in function or external located at /bin/kill. Usage and syntax remain similar regardless internal or external kill command.

A list of common Term signals

Linux and Unix-like operating system supports the standard terminate signals listed below:

  1. SIGHUP (1) – Hangup detected on controlling terminal or death of controlling process. Use SIGHUP to reload configuration files and open/close log files.
  2. SIGKILL (9) – Kill signal. Use SIGKILL as a last resort to kill process. This will not save data or cleaning kill the process.
  3. SIGTERM (15) – Termination signal. This is the default and safest way to kill process.

What is a PID?

A Linux or Unix process is running instance of a program. For example, Firefox is a running process if you are browsing the Internet. Each time you start Firefox browser, the system is automatically assigned a unique process identification number (PID). A PID is automatically assigned to each process when it is created on the system. To find out PID of firefox or httpd process use the following command:

pidof httpd
pidof apache2
pidof firefox

OR use the combination of ps command and grep command:

ps aux | grep httpd
ps aux | grep apache2
ps aux | grep  firefox

Sample outputs:

Fig.01: Find the process ID (PID) of a running firefox program and apache2 server.
Fig.01: Find the process ID (PID) of a running firefox program and apache2 server.

kill command syntax

The syntax is:

kill [signal] PID
kill -15 PID
kill -9 PID
kill [options] -SIGTERM PID

What Linux or Unix permissions do I need to kill a process?

Rules are simple:

  1. You can kill all your own process.
  2. Only root user can kill system level process.
  3. Only root user can kill process started by other users.

kill command examples

In this example, I am going to kill lighttpd server.

Step #1: Find out the PID (process id)

Use the ps or pidof command to find out PID for any program. For example, if process name is lighttpd, you can use any one of the following command to obtain process ID:

pidof lighttpd

Sample outputs:



ps aux | grep lighttpd

Sample outputs:

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

Step #2: kill the process using a PID

The PID # 3486 is assigned to the lighttpd process. To kill the lighttpd server, you need to pass a PID as follows:
# kill 3486
$ sudo kill 3486
This will terminate a process with a PID of 3486.

How do I verify that the process is gone / killed?

Use the ps or pidof command:
$ ps aux | grep lighttpd
$ pidof lighttpd

A note about sending stronger signal # 9 (SIGKILL)

If no signal specified in the kill command, signal # 15 (SIGTERM), is sent by default. So the kill 3486 command is same as the following command:
# kill -15 3486
# kill -SIGTERM 3486

$ sudo kill -15 3486
$ sudo kill -SIGTERM 3486

Sometime signal # 15 is not sufficient. For example, lighttpd may not be killed by signal #15 due to open sockets. In that case process (PID) # 3486 would be killed with the powerful signal # 9:
# kill -9 3486
# kill -SIGKILL 3486

$ sudo kill -9 3486
$ sudo kill -SIGKILL 3486


  • -9 or -SIGKILL – A special kill signal that nearly guarantee to kill the process with the iron fist.

How can I kill two or more PIDs?

The syntax is as follows to kill two or more PIDs as required can be used in a single command:

kill  pid1 pid2 pid3
kill -15  pid1 pid2 pid3
kill -9  pid1 pid2 pid3
kill  -9 3546 5557 4242

Say hello to killall command

This is a Linux only command. to kill processes by name. So no need to find the PIDs using the ‘pidof process’ or ‘ps aux | grep process’ command. Do not use killall command on Unix operating systems. This is a Linux specific command.

The syntax is

killall Process-Name-Here

To kill the lighttpd server, enter:
# killall -15 lighttpd
# killall -9 lighttpd
To kill the Firefox web-browser process, enter:
# killall -9 firefox-bin

As I said earlier, the killall command on UNIX-like system does something else. It kills all process and not just specific process. Do not use killall on UNIX system.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

101 comment

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

    1. use top command it will list the running processes dynamically then press “K” it will ask for process ID(PID) so enter the PID of the process you want to kill.

  2. 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?

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

  4. 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?


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

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

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

    1. When ever you insert you pen-drive to your system, it gets mounted in a particular directory, by default it mounts in /media in most OS. It is quite possible that you have not unmounted that pen-drive from that directory to which it has mounted.

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

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

    1. I was having this same problem. I know you must have use the man and got frustrated after “killall -o 1d” didn’t work. It turns out that the important thing that we missed was that TIME must be a string. In other words …. “killall -o 1.0d”
      That works .

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

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

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

    1. If someone kill the init process, will the run labels work? Will the other processes not effected ??
      Is there any other method?

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

  14. iam getting this errror plz…. help me

    [[email protected] javautils]$ kill 20073
    -bash: kill: (20073) – No such process

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

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

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

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

  19. 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”.

    ‘$ 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.

  20. 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}(28071)
    | |-{firefox}(28072)

    Then I would kill it using:
    kill -9 28060

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

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

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

  24. 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
    # 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.

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

    $ 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

  26. What is the method used for killing init process using kill command?
    During shutdown of the system, the init process is killed by the kernel , I want to know is their any method to kill it using kill command so that i can shutdown my computer on killing the init process.

    please do reply?

  27. You may be looking for this:

    So alt+sysrq+o shuts down the system.

    Otherwise init always has PID 1, so “sudo kill -9 1” or “sudo pkill -9 init” or “sudo killall -9 init” will kill init abruptly. Use -15 instead of -9 or omitt it completely to do it more “gently”, although kill init itself isn’t very gentle method >_<.

  28. Thanks a lot! That is what I’ve been looking for half a year since started playing Nexuiz – it tends to block Gnome sometimes when i try to shut it down, killall didn’t help, now -9 parameter did the job. Before I got here, I had to restart X server using Ctrl+Alt+BckSpc and I was unable to save mo work in other programs. Now i just go: Ctrl+Alt+F1, username, password, killall -9 nexuiz. Thanks again! Terminal rocks :D

  29. I have a PHP CLI script on a UNIX machine that gets terminated after some time.
    How to check if a process is terminated ? where do i look for to check if the process received a termination message ?
    The script is to run for about 5 hrs how do i achieve this.
    i am currently using php script_name.php
    I have read about nohup but is nohup immune to Kill command.
    I think someone either the administrator or the OS is killing the process. Is this possible, if so how do i stop this and make my script run for longer time.

  30. “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).”

    This is inaccurate.

    Mac OS X, one of the nine certified UNIX03 (which, despite the designation, is the current standard) operating systems, uses an implementation of killall which behaves as it does in Linux.

    I’m not pointing this out to be pedantic, it saves keystrokes over the “(find the process’ #pid) `kill -9 #pid`” routine.

  31. How do i kill a program, cleanly. I used killall on transmission, but everytime it starts, it goes on to verify the files. Thanks.

  32. how can i kill ‘inside a script’ my other terminal (having open 2 terminals) and find which is the other one too.????tnx :)

  33. I am using sify internet. they provided one 24online client software for login. it is binary which directly run with help of user name. when 1st time I tried it asks me dns. It create conf file and I got massage that I logged in. for week I used same command like: ./crclient -u xyz123 and I get connected to internet. one day I was connected to internet lost connection due to electricity. I use to logout command like ./crclient -l. I tried to login and getting massage that
    already logedin process id 2951. if I see process using ps -el of pgrep 2951 there is no process. I tried many things like shut down pc. reboot, kept for week off, but still same massage comming from. also I tried to do like install again. I could not understand if there is no process running then why it is saying that it is running. can any one help to stop it.
    How to find out which process is not running?

  34. kill -9 `ps ux | awk ‘/java/ && !/awk/ {print $2}’`

    replace the word java with wather is your process name

  35. There are two types of processes kill can’t remove: Immortal and Zombie, as explained in this note:

    For those who don’t read technical stuff well, it basically says, iirc, a zombie is a child that has died, but not yet reaped by its parent. It uses no resources other than its process entry. Since the zombie is essentially dead, it cannot be killed again. If the parent itself dies before reaping the zombie, the child becomes an orphan and reparented to ‘init’ (the parent of almost all processes). When init waits for its children to die, it will also reap orphaned and its own zombie processes. Zombies are therefor dead processes waiting to be reaped by their parent/init. They should not exist for very long, seldom long enough for ps to list them.

    An Immortal process is one that cannot be signalled because it has a priority higher than the signaling threshold: It won’t get signals sent by kill. Processes that use system critical resources (such as a disk drive) are temporarily given higher priority and therefore cannot be killed while accessing those resources. If the process waits for input from the resource, such as ‘transfer completed’, which never arrives because the devices was removed (for example), then the process can wait forever and becomes Immortal.

    Now, if the parent is an Immortal process, and its child dies (either naturally or via the kill command), the child becomes both a zombie and immortal. It cannot be killed because it is already dead, it exists to be reaped. Its parent will never reap it and can’t be killed because it is blocked by system critical resources and won’t get any signals. Neither can init reap the zombie as an orphan because the parent still exists, and, kill can only kill live processes, not dead ones, so it can’t remove the zombie. Neither can kill remove the parent because the kernel (linux) won’t pass signals to it.

    The only solution in this case is to reboot.

    The difference between a respawned process (one that re-appears after being killed) and a zombie, is that the respawned process will (normally) have a different pid, while the zombie pid will always be the same. If it is a zombie, then the parent should reap it, otherwise go after the parent (ppid). If init is the parent and not reaping the zombie, it probably isn’t healthy and needs attention.

    The difference between a Zombie and an Immortal process is that the zombie is dead and holds no resources, while an Immortal process has a high priority that prevents it from getting signals, is alive, and holding/consuming resources. Both zombie and immortal processes retain their pid after being ‘killed’.

    Mostly, kill works just fine to remove buggy programs, but its the stubborn zombies and (more importantly) immortals where kill fails. I suspect the reason is that kill does not actively kill anything, but passively sends signals, assuming the target will ‘do the right thing’. For zombies and Immortals, they can’t or won’t. Apparently there is no nuke to smash these processes and mark all their resources as ‘available’. Perhaps a reboot is safer than risking the kernel screwing up its resource allocations and (silently) trashing system/user data?

    I did find your article informative, the pidof with kill is exactly what I’ve been looking for. The answer to killing zombies and immortals is not what I wanted, but at least I know I’m not missing something (am I?).

  36. hai,
    i am first time using linux,please tell me all the commands for linux and main usage for current process for killing.

  37. Hello!

    Anyone knows how to kill all the processes from a specific username from TOP command? Usually you have to indicate the PID, but i would like to kill all the PIDs from a user.


  38. Can anyone tell me how to kill users who are logged into the terminal (I.E.: tty), I currently show eight users logged in and there is only one profile besides root. There should not be eight users. I have one terminal open. Thanks for your help.

  39. Hello i not able to get the PID of the process which i need to kill.
    I used pidof (process name),ps -A ,top command but i not got pid of the process

  40. Nabil –

    You are a total stud. That’s what I was looking for … the only way to kill a process by name (not PID number) that worked.

    For those who didn’t get it the first time…

    kill -9 `ps ux | awk ‘/java/ && !/awk/ {print $2}’`

    Then replace the word java with wather is your process name.

    I used this to kill chromium gracefully (with a kill -15), then restart it 5 seconds later … that gets rid of the pesky “Chromium didn’t shut down correctly” message.

  41. For what purpose we use -9 option in kill command , what is the difference between kill and kill -9 .

  42. This so helpful! Thank you :). I used to use command sudo killall skype and wondering why it did not work haha.

  43. Hi Friends i know how to kill process , but -9 option for what purpose we are using , how to clear zombie process in process tables ?

  44. in a shell, press strg+c to stop (e.g. if you started an extraction that should have been started as root, but you started it as user)

  45. Hey guys! I have a process that changes PID every time I kill its parent. I have also tried the process itself. The conditions are:
    I am using screen
    The process is being used but wont tell me whats using it even if I try a ps afx

    Any help would be wonderful as it is taking up a important port on the server and I cant run any other programs with it on that port. Thanks!

  46. Hi,

    I have a requirement like killing some 20 to 30 process from linux. suppose if i want to kill a single process i will use kill -9 . Is there any way to proceed on killing multiple process related to same instance.

    Note: in the same linux server i have 3 Oracle Instances are running.. NO other instance should be affected for this.

    Can anyone help on this.?


  47. Hi all!,
    I like your comments .
    i am running a MIP model using glpk package in Ubuntu terminal,but i got the text killed at the end.
    what should i do .i’m usinng a matrix dimension of 95×95.
    when using matrix dimension 40×40 the package works successfully.
    help please!

  48. Hi,
    I’m wondering how to kill a tcp connection by entering the connection PID.Please help me.

  49. may i know how to kill a unknown pid.
    while entering ps command it is showing that login details but the program is running on another telnet in that the program is in middle ,it is stucked .can you please suggest some one..

  50. [[email protected] ~]# yum update
    Loaded plugins: fastestmirror, security
    Existing lock /var/run/ another copy is running as pid 4562.
    Another app is currently holding the yum lock; waiting for it to exit…
    The other application is: yum
    Memory : 44 M RSS ( 86 MB VSZ)
    Started: Wed Jun 27 06:05:35 2012 – 00:01 ago
    State : Uninteruptable, pid: 4562

    Exiting on user cancel.
    [[email protected] ~]# kill -9 4562
    [[email protected] ~]# ps aux|grep yum
    root 4562 0.0 7.9 87792 44764 pts/1 D+ 06:05 0:00 /usr/bin/python /usr/bin/yum update
    root 4792 0.0 0.1 4016 676 pts/2 R+ 06:05 0:00 grep yum
    [[email protected] ~]#

  51. Hey i want diffrent multipal pid Of Firefox Bcz I want Close Only ne window(Not Tab) of Firefox
    ans Me as Soon as fast

  52. Thaks..its very funny all this ..killall.
    ..its sound to kill em the clasic metallika disk..sorry,i rmember
    the unix philosophy:“ unix:uniqie,only one way to do
    .something…well,there many..amd thatts its funny too
    by the way good post..its solve my problem too

  53. Hi Guys,
    i need to know the process id of the last killed process and who killed the Process?. where i can get that?

    please help me…


  54. Hi,

    1. How can i kill 50 old pid’s of particular precess ?

    2. How can i kill 50 old pid’s of particular process when it reached to 100 using cron ?

    Thanks in advance.


  55. How can i kill 50 old pid’s of particular process when it reached to 100 using cron script?
    ps -elf | grep myscript | head -n 50 | awk ‘{print $4}’ |xargs kill -9

    Mudassir Aftab

  56. Don’t forget we also have `killall’ which will terminate processes by process name, by default with a SIGTERM.

  57. Hi,

    I have a list of servers for example say 1 to 10
    How would i able to see the process id’s for all at a time

    Is there any command to get it


  58. Got below message on centos 6.3.
    usage: kill [ -s signal | -p ] [ -a ] pid …
    kill -l [ signal ]

    how to kill please suggest

  59. I have started the processes in windows with a top command but I failed to stop it. Please I need a help.

    1. Pauline, this is the wrong forum for your question, but just type ‘q’ to quit the top program.

      Google “man top” and you’ll find this quite near the beginning:

      When operating top, the two most important keys are the help (‘h’
      or ‘?’) key and quit (‘q’) key. Alternatively, you could simply
      use the traditional interrupt key (‘^C’) when you’re done.

  60. Can we pipe the process id to kill command?
    I tried doing like
    sudo kill -9 | pidof motion
    It is not working, any other ideas.

Comments are closed.