The Linux kill command is used to kill PID’s or process ID’s. This command is beneficial for numerous reasons typically for run away processes, processes caught in some sort of loop, to kick users from a system, or any other number of reasons.
Typically kill is used in the below format with 12345 being the PID in this example.
- [root@server ~]# kill 12345
If the process will not die from using the above command the -9 switch can be added to force it to stop as shown below.
- [root@server ~]# kill -9 12345
There are a total of 60 signals that can be used as switches with the kill command. The below command was issued on a CentOS 5.2 server with the -l switch to detail all of the available signals.
- [root@server ~]# kill -l
- 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
- 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
- 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
- 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT
- 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
- 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU
- 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH
- 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN
- 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4
- 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
- 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12
- 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14
- 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10
- 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6
- 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
- 63) SIGRTMAX-1 64) SIGRTMAX
To get a listing of processes and their respective PID’s you would use the “ps” command as shown below again on a CentOS 5.2 server.
- [root@server ~]# ps -ef
- UID PID PPID C STIME TTY TIME CMD
- root 1 0 0 Apr21 ? 00:00:09 init [3]
- root 2 1 0 Apr21 ? 00:02:19 [migration/0]
- root 3 1 0 Apr21 ? 00:00:03 [ksoftirqd/0]
- root 4 1 0 Apr21 ? 00:00:00 [watchdog/0]
- root 5 1 0 Apr21 ? 00:00:11 [events/0]
- root 6 1 0 Apr21 ? 00:00:00 [khelper]
- root 7 1 0 Apr21 ? 00:00:00 [kthread]
- root 9 7 0 Apr21 ? 00:00:00 [xenwatch]
- root 10 7 0 Apr21 ? 00:00:00 [xenbus]
- root 16 7 0 Apr21 ? 00:00:34 [migration/1]
- root 17 7 0 Apr21 ? 00:00:01 [ksoftirqd/1]
- root 18 7 0 Apr21 ? 00:00:00 [watchdog/1]
- root 19 7 0 Apr21 ? 00:00:03 [events/1]
- root 20 7 0 Apr21 ? 00:00:24 [migration/2]
- root 21 7 0 Apr21 ? 00:00:00 [ksoftirqd/2]
- root 22 7 0 Apr21 ? 00:00:00 [watchdog/2]
- root 23 7 0 Apr21 ? 00:00:04 [events/2]
- root 24 7 0 Apr21 ? 00:00:24 [migration/3]
- root 25 7 0 Apr21 ? 00:00:01 [ksoftirqd/3]
- root 26 7 0 Apr21 ? 00:00:00 [watchdog/3]
- root 27 7 0 Apr21 ? 00:00:03 [events/3]
- root 32 7 0 Apr21 ? 00:00:00 [kblockd/0]
- root 33 7 0 Apr21 ? 00:00:00 [kblockd/1]
- root 34 7 0 Apr21 ? 00:00:00 [kblockd/2]
- root 35 7 0 Apr21 ? 00:00:00 [kblockd/3]
- root 36 7 0 Apr21 ? 00:00:00 [cqueue/0]
- root 37 7 0 Apr21 ? 00:00:00 [cqueue/1]
- root 38 7 0 Apr21 ? 00:00:00 [cqueue/2]
- root 39 7 0 Apr21 ? 00:00:00 [cqueue/3]
- root 42 7 0 Apr21 ? 00:00:00 [kseriod]
- root 103 7 0 Apr21 ? 00:06:43 [kswapd0]
- root 104 7 0 Apr21 ? 00:00:00 [aio/0]
- root 105 7 0 Apr21 ? 00:00:00 [aio/1]
- root 106 7 0 Apr21 ? 00:00:00 [aio/2]
- root 107 7 0 Apr21 ? 00:00:00 [aio/3]
- root 355 7 0 Apr21 ? 00:00:00 [kpsmoused]
- root 637 7 0 Apr21 ? 00:00:00 [kmirrord]
- root 1138 7 0 Apr21 ? 00:04:19 [kjournald]
- root 1231 7 0 Apr21 ? 00:00:00 [khubd]
- root 1243 7 0 Apr21 ? 00:00:00 [kauditd]
- root 1272 1 0 Apr21 ? 00:00:00 /sbin/udevd -d
- root 1822 7 0 Apr21 ? 00:00:00 [kmpathd/0]
- root 1823 7 0 Apr21 ? 00:00:00 [kmpathd/1]
- root 1824 7 0 Apr21 ? 00:00:00 [kmpathd/2]
- root 1825 7 0 Apr21 ? 00:00:00 [kmpathd/3]
- root 2064 1 0 Apr21 ? 00:01:53 syslogd -m 0
- root 2067 1 0 Apr21 ? 00:00:00 klogd -x
- dbus 2082 1 0 Apr21 ? 00:00:00 dbus-daemon --system
- 68 2154 1 0 Apr21 ? 00:00:00 hald
- root 2155 2154 0 Apr21 ? 00:00:00 hald-runner
- root 2167 1 0 Apr21 tty1 00:00:00 /sbin/mingetty tty1
- root 5573 1 0 Apr25 ? 00:00:57 /usr/libexec/postfix/master
- postfix 5576 5573 0 Apr25 ? 00:00:06 qmgr -l -t fifo -u
- ntp 17997 1 0 Apr28 ? 00:00:07 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
- root 28376 1 0 May21 ? 00:00:02 crond
- root 23830 1 0 Jun18 ? 00:14:11 /usr/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd.pid -a
- web 9021 1 0 Jul10 ? 00:00:13 tail -f haloror/log/production.log
- root 1720 1 0 Aug03 ? 00:00:09 /usr/sbin/sshd
- postgres 28334 1 0 Aug04 ? 00:17:40 /usr/bin/postmaster -p 5432 -D /var/lib/pgsql/data
- postgres 28348 28334 0 Aug04 ? 00:23:45 postgres: logger process
- postgres 28350 28334 0 Aug04 ? 00:00:59 postgres: writer process
- postgres 28351 28334 0 Aug04 ? 00:00:20 postgres: wal writer process
- postgres 28352 28334 0 Aug04 ? 00:00:16 postgres: autovacuum launcher process
- postgres 28353 28334 0 Aug04 ? 00:04:09 postgres: stats collector process
- root 14341 1 0 Oct09 ? 00:00:18 xinetd -stayalive -pidfile /var/run/xinetd.pid
- root 11106 1 0 Nov06 ? 00:00:19 lshttpd
- root 11107 11106 0 Nov06 ? 00:00:00 httpd (lscgid)
- web 11108 11106 0 Nov06 ? 00:01:16 lshttpd
- web 11109 11108 0 Nov06 ? 00:00:42 ruby /var/lsws/fcgi-bin/RailsRunner.rb
- web 11110 11108 0 Nov06 ? 00:00:13 ruby /var/lsws/fcgi-bin/RailsRunner.rb
- web 11111 11108 0 Nov06 ? 00:00:12 ruby /var/lsws/fcgi-bin/RailsRunner.rb
- root 19679 7 0 Nov08 ? 00:00:00 [pdflush]
- root 24260 7 0 00:06 ? 00:00:00 [pdflush]
- root 12558 1720 0 03:13 ? 00:00:00 sshd: gateway [priv]
- gateway 12570 12558 0 03:13 ? 00:00:00 sshd: gateway
- root 12619 1720 0 03:14 ? 00:00:00 sshd: root@pts/0
- root 12629 12619 0 03:14 pts/0 00:00:00 -bash
- root 12653 1720 0 03:14 ? 00:00:00 sshd: root@pts/2
- root 12658 12653 0 03:14 pts/2 00:00:00 -bash
- root 12720 12629 0 03:15 pts/0 00:00:00 su - web
- web 12721 12720 0 03:15 pts/0 00:00:00 -bash
- postfix 13576 5573 0 03:21 ? 00:00:00 pickup -l -t fifo -u
- root 14726 1720 0 03:33 ? 00:00:00 sshd: root@pts/3
- root 14735 14726 0 03:33 pts/3 00:00:00 -bash
- root 14995 12658 0 03:35 pts/2 00:00:00 su - web
- web 14996 14995 0 03:35 pts/2 00:00:00 -bash
- web 14533 11109 0 04:13 ? 00:00:11 ruby /var/lsws/fcgi-bin/RailsRunner.rb
- postgres 14534 28334 0 04:13 ? 00:00:04 postgres: postgres haloror 127.0.0.1(44825) idle
- postfix 28252 5573 0 04:49 ? 00:00:00 smtpd -n smtp -t inet -u
- postfix 28253 5573 0 04:49 ? 00:00:00 proxymap -t unix -u
- root 28288 14735 0 04:50 pts/3 00:00:00 ps -ef
Using the above information as an example then say you wanted to kick any of the gateway user’s SSH connections off the server you would issue the below command.
- [root@server ~]# ps -ef | grep gateway
- gateway 12570 12558 0 03:13 ? 00:00:00 sshd: gateway
- [root@server ~]# kill 12570
The gateway users SSH connection would now be terminated.
For the entire kill manpage please visit the QD link located here.
ммм не думал …
Does the comment mean the article helped you? Regardless thank you for the feedback.
hm. really like it.
I’m just curious, WTF is the point of doing something like this? Maybe if you titled it “One ultra simple example of using kill from the command line for Total Noobs” it would have at least had some entertainment value. Seriously dude, “Explained in Detail”? Where do you get off?
Hello Justin,
Even more funny is the fact that you found the time to locate the article and leave a comment. Not sure what you mean by where do I get off. I will chalk it up as you are having a bad day and needed to vent. Regardless thanks for taking the time to visit our site.
Thanks.
alex
No, it’s not funny, I was searching for a more detailed list of signals for kill and what they are typically used for since the kill documentation is fairly sparse. What I mean by where do you get off is that you are proclaiming that you are explaining kill “in detail” and have titled your “article” as such. The fact of the matter is that this ‘explanation’ is LESS comprehensive than the supplied documention, there is really zero chance that anyone will ever benefit from this. YES I was having a bad day, and the last thing I needed was to waste time reading lame crap like this, I didn’t “find the time to locate the article and leave a comment”. I was searching for something useful, not “lame attempts to appear knowledgeable” and yet this crap came up anyway, so please do tell, exactly WHAT is the point of writing something like this? Seriously, I run across this kind of thing all the time and I can’t for the life of me figure out what motivates you people. You could have simply instructed readers to run “man kill” and they would have gotten FAR more information themselves.
Justin Buser — is that short for “Justin Bieber user”? Hmmm, maybe it stands for Justin Bieber abuser — I always wondered who was f-ing that kid in the ass.
I understand that the article doesn’t contain as much detail as you were looking for, but when that is the case, you leave and look elsewhere. You don’t leave a comment being a complete jackass about it. The article is still a useful tool for people (especially new Linux users) looking for a quick reference, complete with an example, of how to use the kill command to stop a process (or even kill an ssh connection).
Seriously? A month later? You’re going to come back to this site and be a jackass a month after the author’s response to your initial temper tantrum? BTW, the author pretty much took the high road in dealing with you. Next time you’re having a bad day, I recommend getting a good blow job from your teenage boyfriend. It takes all the stress away. Give him a nice face wash — I hear he look’s great all white and glistening. You can even have your mom come down to your bedroom in the basement and videotape the whole thing for you — sort of a keepsake that you can watch over and over again the next time you’re tempted to post something at 5:16 AM!
Take care,
Your Butt-Buddy
Hello Justin Buser,
Still not sure why you find it necessary to rant on a post aimed to help others. In my experience I have found that there are plenty of people that don’t understand the basic concepts of commands such as kill and writing out an example where it explains even the most basic usage is helpful to others. The same users that have trouble understanding the basic concept of the command would be the same users that might not even know how to use the man page. If you had some more useful information it would be beneficial to use the energy displayed above to post something helpful for others instead of attempting to belittle the post. Regardless everyone is entitled to their opinion and the only purpose on my end is to post articles that help others. I have found that being respectful and sharing things I learn pays dividends back to me in the end.
Thanks.
alex