How To Use Linux Kill Command

March 20, 2011 | By
| 1 Reply More

Linux Kill Command

The word kill itself shows its clear meaning and purpose. In Linux, kill command is used for terminating the process. The command kill sends the specified signal to the specified process or the process group. First we need find PID of the process, so that we can terminate the process. In our example, we will try to kill the crond process. This command is used when the process is not stopped graciously or abrupt the process or used to kill hung process.

Example:-

[root@localhost init.d]# ps -eaf | grep -i crond
root 2094 1 0 02:51 ? 00:00:00 crond
root 7089 6655 0 06:07 pts/3 00:00:00 grep -i crond

[root@localhost init.d]# kill 2094

In above example, we have come to know the PID of the crond process and now this will terminate or kill the process using kill command graciously.

Options

-l This option gives list of the signal names l

[root@localhost init.d]# 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

-s specify the signal to send.

[root@localhost init.d]# kill -s SIGKILL 7109
Or
[root@localhost init.d]# kill -s 9 7109

Above two commands kills process id 7109 forcibly.

Below, I have given a scenario where I need to kill a particular process. I have a script that is running with 500 process.

[root@localhost]#ps -ef | grep compress.sh | wc -l
500

You can kill 500 process in one step !!!!

#ps -ef | grep compress.sh | tr -s " " | cut -d" " -f2 | xargs kill -9

Filed Under : HOWTOS, LINUX COMMANDS, LINUX HOWTO

Tagged With :

Free Linux Ebook to Download

Comments (1)

Trackback URL | Comments RSS Feed

  1. ravi says:

    how to kill only 49 processes out of 50 processes and keeping last 1 process live?

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.