Selected topic

Kill

Process Management

Prefer practical output? Use related tools below while reading.

In Linux, a process is an instance of a program that is running. The kill command is used to send signals to processes, which can be used to terminate, stop, or suspend them.

Kill Command Syntax:


kill [options] <process_id>

Example 1: Terminating a Process


Let's say we have a process with ID 1234 running in the background. We can kill it using the following command:

$ kill 1234

This will send a SIGTERM signal to the process, which is the default signal sent by kill. The process will be terminated if it doesn't exit on its own within a short period of time.

Example 2: Killing Multiple Processes


We can also kill multiple processes at once by separating their IDs with spaces:

$ kill 1234 5678 9012

This will send the same signal to all three processes.

Options:


The kill command has several options that allow us to specify the type of signal to be sent. Here are a few examples:

  • -9 or SIGKILL: This is a stronger signal than SIGTERM and cannot be caught by the process. It will terminate the process immediately, without giving it a chance to exit cleanly.
  • -15 or SIGTERM: This is the default signal sent by kill. It tells the process that it should exit, but gives it a chance to clean up before doing so.

Example 3: Killing with a Specific Signal

Let's say we want to kill a process with ID 1234 using the SIGKILL signal:
$ kill -9 1234

This will send a strong signal to the process, which cannot be caught or ignored. The process will be terminated immediately.

In summary, the kill command is used to terminate processes by sending signals to them. We can specify the type of signal to be sent using options like -9 for SIGKILL or -15 for SIGTERM.