Skip to main content

Command Palette

Search for a command to run...

Cheatsheet & Examples: kill

Updated
2 min read
H

I am a developer from Malaysia. I work with PHP most of the time, recently I fell in love with Go. When I am not working, I will be ballroom dancing :-)

The kill command is a utility in Unix-like operating systems used to send signals to processes. Signals are a form of inter-process communication that can be used to terminate, suspend, or otherwise control processes.

Terminate a Process (SIGTERM)

Example Usage: kill <PID>

What it does: Sends the SIGTERM signal (termination signal) to the process with the specified process ID (PID), requesting it to terminate gracefully.

Command-line Arguments Explained:

  • <PID>: The process ID (a numerical identifier) of the process you want to terminate.

Forcefully Terminate a Process (SIGKILL)

Example Usage: kill -9 <PID> or kill -KILL <PID>

What it does: Sends the SIGKILL signal (kill signal) to the process with the specified PID. This signal immediately terminates the process without allowing it to perform any cleanup operations. Use this as a last resort, as it can lead to data loss or corruption if the process is in the middle of writing data.

Command-line Arguments Explained:

  • -9 or -KILL: Specifies the signal to send; in this case, SIGKILL, which is signal number 9.
  • <PID>: The process ID of the process to be terminated.

Send a Specific Signal

Example Usage: kill -<SIGNAL_NUMBER> <PID> or kill -s <SIGNAL_NAME> <PID>

What it does: Sends a specific signal to the specified process. The signal can be identified by its number or name.

Command-line Arguments Explained:

  • -<SIGNAL_NUMBER>: Specifies the signal to send, using its numeric value (e.g., -15 for SIGTERM).
  • -s <SIGNAL_NAME>: Specifies the signal to send, using its symbolic name (e.g., -s TERM or -s SIGTERM for the termination signal).
  • <PID>: The process ID of the target process.

Suspend a Process (SIGSTOP)

Example Usage: kill -STOP <PID>

What it does: Sends the SIGSTOP signal, causing the process to pause its execution. The process can later be resumed with the SIGCONT signal.

Command-line Arguments Explained:

  • -STOP: Specifies the signal to send (SIGSTOP).
  • <PID>: The PID of the process to be suspended.

Resume a Suspended Process (SIGCONT)

Example Usage: kill -CONT <PID>

What it does: Sends the SIGCONT signal, resuming the execution of a previously suspended process.

Command-line Arguments Explained:

  • -CONT: Specifies the signal to send (SIGCONT).
  • <PID>: The PID of the process to resume.

List Available Signals

Example Usage: kill -l

What it does: Lists all the available signals that can be used with the kill command and their corresponding numeric values.

Command-line Arguments Explained:

  • -l: The list flag.

More from this blog

Hong's Tech Blog

110 posts

The blog is older than you know. I prefer counting from the emergence of one integral anomaly to the emergence of the next, in which case this is the forth version.