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.

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.