Linux kill Command: Send a Signal to a Process ID

kill sends a signal to the specified process ID (PID) or shell job. Contrary to its name, its default action is not a forceful termination but a termination request via SIGTERM.

What is the kill command?

In Bash, kill is provided as a shell built-in command. How a process reacts to a received signal depends on the type of signal and the program's implementation. If termination is necessary, first try the normal termination procedure and SIGTERM.

Basic syntax

kill [-signal] PID...

Installed implementations and options may vary depending on the distribution. Use help kill to check the description on the current system.

Examples

Checking PID

First, verify that the process is still the intended task.

ps -p 1234 -o pid,user,stat,cmd

Requesting normal termination

Explicitly send the default SIGTERM.

kill -TERM 1234

List of Available Signals

Check the names of signals in the current shell implementation.

kill -l

Check the PID and send a signal

kill sends a signal to a PID, not a name. The 12345 below is an example number, so when actually executing, first check your test process PID with ps and replace it.

ps -p 12345 -o pid,stat,comm
kill -TERM 12345
ps -p 12345 -o pid,stat,comm

On the first query, the target will be displayed, and when kill is successful, there is usually no output. After a normal termination is complete, the last query will show only the header or indicate that there is no target. This is a sample flow, and the time it takes to fully terminate depends on the process.

SIGTERM is the default termination request allowing cleanup. SIGKILL skips cleanup, so use it as a last resort. PIDs can be reused, so blindly trusting an old number could result in sending a signal to a different process.

Main Options and Format

Options/Format Description
-TERM Request normal termination of a process.
-INT Send a signal corresponding to a terminal interrupt.
-HUP Send a hangup signal, which is interpreted differently depending on the program.
-KILL Force an immediate termination. Cleanup operations may be skipped.
-0 Check existence and permissions without sending an actual termination signal.

Precautions when using

Since PIDs can be reused, do not use a PID that was long recorded. Failure of kill -0 may be due to absence of the process as well as lack of permissions. kill -KILL is a last resort and may interrupt data cleanup or file writing.

Frequently Asked Questions

What if you run kill but the process remains?

It may be ignoring SIGTERM or in the process of shutdown cleanup. Check the status and logs and review the proper service shutdown method first.

Official Documentation

You can check the exact behavior of options and implementation differences in the official kill documentation.

More in This Category
Linux resolvectl Command: Inspect systemd DNS Resolution

Linux resolvectl Command: Inspect systemd DNS Resolution

Learn how to inspect systemd DNS Resolution with the Linux resolvectl command, including practical examples, key options, and important precautions.

Linux dig Command: Query DNS Records in Detail

Linux dig Command: Query DNS Records in Detail

Learn how to query DNS Records in Detail with the Linux dig command, including practical examples, key options, and important precautions.

Linux sync Command: Flush Buffered Writes to Storage

Linux sync Command: Flush Buffered Writes to Storage

Learn how to flush Buffered Writes to Storage with the Linux sync command, including practical examples, key options, and important precautions.

Linux ethtool Command: Inspect Network Link and Driver Settings

Linux ethtool Command: Inspect Network Link and Driver Settings

Learn how to inspect Network Link and Driver Settings with the Linux ethtool command, including practical examples, key options, and important precautions.

Linux Tutorial / Compare Files with diff and cmp

Linux Tutorial / Compare Files with diff and cmp

Use diff and cmp to compare two files, read unified diff output, and distinguish a detected difference from an actual command error.

Linux zypper Command: Manage Packages on openSUSE and SUSE

Linux zypper Command: Manage Packages on openSUSE and SUSE

Learn how to manage Packages on openSUSE and SUSE with the Linux zypper command, including practical examples, key options, and important precautions.

Linux nmap Command: Scan Authorized Hosts and Ports

Linux nmap Command: Scan Authorized Hosts and Ports

Learn how to scan Authorized Hosts and Ports with the Linux nmap command, including practical examples, key options, and important precautions.

Linux pkill Command: Signal Processes by Name

Linux pkill Command: Signal Processes by Name

Learn how to signal Processes by Name with the Linux pkill command, including practical examples, key options, and important precautions.

Linux grep Command: Search Text and Filter Command Output

Linux grep Command: Search Text and Filter Command Output

Learn how to use the Linux grep command to search files for text or regular expressions and filter command output, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux free Command: Check Memory and Swap Usage

Linux free Command: Check Memory and Swap Usage

Learn how to use the Linux free command to inspect available memory, used memory, cache, and swap usage, with essential options, practical examples, output interpretation, and common troubleshooting tips.