Different commands are used to send signals to processes to terminate or “kill” them. This is necessary when a process becomes unresponsive (hangs), causes system instability, or fails to relinquish control over a file you’re trying to modify.

Using the pid number to terminate processes

You can use the kill command with the process table to end processes. By entering kill followed by the PID, you can terminate specific processes. However, the process table may display processes that do not belong to you. As a user, you can use the kill command only with processes that you own. As root, you can kill any process.

Kill Signals

There are many ways to kill a process, each one mapped to a signal. This signal determines how to kill the process. Some signals are more appropriate than others in certain situations. For example, you may wish to terminate a process gracefully, giving it time to clean up any last activities. However, some processes will ignore this signal or simply fail to terminate in a reasonable amount of time. For that, you may have to issue a more aggressive signal.

There are many different kill signals. Each signal has a name and one or more corresponding number values; you can use either with the kill command. Some of the most common signals are described below:

1. SIGINT (2)
– Interrupts process from terminal.
– Can be caught or ignored.
– Same as pressing Ctrl+C

2. SIGKILL (9)
– Kills process immediately.
– Cannot be caught or ignored.
– Last resort.

3. SIGTERM (15)
– Terminates process.
– Can be caught or ignored.
– Sent from program and not terminal.

4. SIGSTOP (17, 19, 23)
– Pause process.
– Cannot be caught or ignored.
– Sent from program and not terminal.

5. SIGSTP (18, 20, 24)
– Pauses process from terminal.
– Can be caught or ignored.
– Same as pressing Ctrl+Z.

Demo of kill signals

The following are some examples of implementing kill signals. To terminate a process with ID 921 gracefully:

Failing that, to kill the process immediately:

Alternatively, to pause rather than remove the process entirely:

kill Command Examples

1. To get the list of signals:

# kill -l 
 1) SIGHUP	 2) SIGINT	     3) SIGQUIT	 4) SIGILL
 5) SIGTRAP	 6) SIGABRT	     7) SIGEMT	 8) SIGFPE
 9) SIGKILL	10) SIGBUS	    11) SIGSEGV	12) SIGSYS
13) SIGPIPE	14) SIGALRM	    15) SIGTERM	16) SIGURG
17) SIGSTOP	18) SIGTSTP	    19) SIGCONT	20) SIGCHLD
21) SIGTTIN	22) SIGTTOU	    23) SIGIO	24) SIGXCPU
25) SIGXFSZ	26) SIGVTALRM	27) SIGPROF	28) SIGWINCH
29) SIGINFO	30) SIGUSR1	    31) SIGUSR2

2. To send a particular signal:

3. To specify the list of processes for kill: