kill command
kill
- send a signal to a process. The default signal for kill is TERM.
The kill
command in Linux is a utility used to terminate processes by sending signals to them. It’s essential for stopping misbehaving programs, freeing resources, or managing tasks identified with tools like ps.
Usage: kill [options] [pid] [...]
PID
: The process ID(s) to target (find withps
).options
: Flags to specify signals (e.g.,-9
for SIGKILL).
Examples
-
Basic Usage
Send the default signal (
SIGTERM
) to a process to request termination.kill 1234
- Sends
SIGTERM
to process with PID 1234. SIGTERM
politely asks the process to stop, allowing it to clean up.
Find PID First:
ps aux | grep firefox
- Output (example):
alice 5678 1.2 3.4 123456 78901 ? S 10:00 0:01 firefox
- Then:
kill 5678
- Sends
-
Forcing Termination
Use
-9
(or-SIGKILL
) to forcefully stop a process.kill -9 5678
- Sends
SIGKILL
, immediately terminating PID 5678 without cleanup. - Use this as a last resort—processes can’t ignore it.
- Sends
-
Specifying Signals
kill
supports various signals. Use-SIGNALNAME
or-NUMBER
.Common Signals:
Signal Number Description SIGTERM
15 Terminate gracefully (default) SIGKILL
9 Force immediate termination SIGHUP
1 Hang up (reload config for some daemons) SIGINT
2 Interrupt (like Ctrl+C) Example with Signal Name:
kill -SIGHUP 1234
- Sends
SIGHUP
to reload configuration (e.g., for some servers).
Example with Number:
kill -1 1234
- Same as above.
- Sends
-
Listing Signals
See all available signals with
-l
(list).kill -l
- Output (partial):
1) SIGHUP 2) SIGINT 3) SIGQUIT 9) SIGKILL 15) SIGTERM
- Numbers match signal names.
- Output (partial):
-
Killing Multiple Processes
Pass multiple PIDs to terminate several processes at once.
kill 1234 5678 9012
- Stops all listed PIDs with
SIGTERM
.
- Stops all listed PIDs with
-
Using with Process Names (via
pkill
)While
kill
uses PIDs,pkill
(a related tool) targets processes by name.pkill firefox
- Sends
SIGTERM
to all Firefox processes. - Use
pkill -9 firefox
forSIGKILL
.
- Sends
To get help related to the kill
command use --help
option
$ kill --help
kill: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
Send a signal to a job.
Send the processes identified by PID or JOBSPEC the signal named by
SIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is present, then
SIGTERM is assumed.
Options:
-s sig SIG is a signal name
-n sig SIG is a signal number
-l list the signal names; if arguments follow `-l' they are
assumed to be signal numbers for which names should be listed
-L synonym for -l
Kill is a shell builtin for two reasons: it allows job IDs to be used
instead of process IDs, and allows processes to be killed if the limit
on processes that you can create is reached.
Exit Status:
Returns success unless an invalid option is given or an error occurs.
For more details, check the manual with man kill