Sunday, May 20, 2012

UNIX Kill Command Examples

How do I send a KILL signal to a process under UNIX operating systems?

Use the kill command to send a signal to each process specified by a pid (process identifier). The default signal is SIGTERM (terminate the process).

Syntax

kill PID
kill -s signalName PID
kill -9 PID

Common UNIX Signal Names and Numbers

All available UNIX signals have different names, and are mapped to certain numbers as described below.
NumberName DescriptionUsed for
0SIGNULLNullCheck access to pid
1SIGHUPHangupTerminate; can be trapped
2SIGINTInterruptTerminate; can be trapped
3SIGQUITQuitTerminate with core dump; can be
9SIGKILLKillForced termination; cannot be trapped
15SIGTERMTerminateTerminate; can be trapped
24SIGSTOPStopPause the process; cannot be trapped
25SIGTSTPTerminalstop Pause the process; can be
26SIGCONTContinueRun a stopped process
Note the specific mapping between numbers and signals can vary between Unix implementations, please see the manual page entry signal(5), by typing the following command:
man 5 signal

Examples: Send a Kill Single To Process ID 1414

Use the following command to kill pid 4242 and exit gracefully:
kill 4242
To find pid of any job or command use ps command:
ps | grep command
ps aux | grep command
ps aux | grep apache
The following all are equivalent commands with -9 SIGKIL (i.e forcefully kill 1414 process):
kill -s SIGKILL 1414
kill -s KILL 1414
kill -s 9 1414
kill -SIGKILL 1414
kill -KILL 1414

No comments:

Post a Comment