Unix Kill Command

What is it?

It is a popular Unix and Linux command that is often used by system administrators to send signals to a running process or daemon. A signal is a form of inter-process communication that is used in the Unix and Linux operating systems to notify a daemon that an event has occurred. One of the jobs of the operating system is to notify and interrupt the daemon and allow the daemon to take action. This command can be sent from a shell terminal or from a shell script such as the Bourne, Korn, Bash, or C shell.


What is it useful for?

There are many uses for the kill command. System administrators commonly use it in scheduled at jobs or crontab jobs for automation. One of the most common uses is to terminate a daemon that appears to be hung up. SIGTERM and SIGKILL signals are used with the kill command to terminate a daemon. SIGTERM signal is more graceful than SIGKILL because it nicely requests the termination of a daemon. SIGTERM gives the daemon an opportunity to cleanup and close files before it begins to terminate. SIGTERM can be caught or ignored by a daemon. For this reason, SIGTERM is normally used in init command to perform a graceful reboot or shutdown before it uses SIGKILL. Unlike SIGTERM, a SIGKILL signal forces the daemon to stop immediately. A SIGKILL signal can not be caught or ignored. Another common use for this command is through the SIGHUP signal, which requests the daemon to re-load its configuration file. This is especially useful in a production environment when users need to modify the configuration file of Apache or Sendmail and wish to re-read the configuration file without restarting the daemon.


The Syntx

The kill command is implemented slightly different between different flavors of the Unix and Linux operating systems. However, they share one common syntax.


Syntax: kill -n PID

Where -n is the signal number, and PID is the daemon ID. The signal number can be any of the following:

1 - SIGHUP: hang up
2 - SIGINT: interrupt
3 - SIGQUIT: quit
6 - SIGABRT: abort
9 - SIGKILL: immediately terminate a daemon; signal can not be caught or ignored
14 - SIGALRM: alarm clock
15 - SIGTERM: software termination signal

How do you find the process id (PID)?

One of the most common uses is to terminate hanging daemons. For instance, you want to stop a daemon called LALALA. To find out the PID of the LALALA, you execute the "ps -ef | grep LALALA" command from a shell terminal. The "ps -ef | grep LALALA" command lists all processes running in a full listing format, which includes the process id. Then the command filters out the process name in "grep LALALA".

Example: ps -ef | grep LALALA
Result:
ID PID PPID C STIME TTY TIME CMD
LALALA 7209 32097 0 12:17 pts/87 00:00:00 ps -ef

The PID of LALALA is 7209, which is usually listed right after the process name.

To send a SIGKILL signal to PID 7209, you execute the command “kill -9 7209”.

 
Privacy | Contact

Copyright - 2013 KillUnix.com - All Rights Reserved.