Kill a process by specifying its PID, either via a signal or forced termination.
Syntax kill [-s sigspec] [-n signum] [-sigspec] jobspec or pid kill -l [exit_status] kill -l [sigspec] Key -l List the signal names -s Send a specific signal -n Send a specific signal number
Send a signal specified by sigspec or signum
to the process named by job specification jobspec or process ID pid.
sigspec is either a case-insensitive signal name such as
SIGINT (with or without the
SIG prefix) or a signal number; signum is a signal number.
If sigspec is not present,
SIGTERM is used (Terminate).
If any arguments are supplied when '-l' is given, the names of the signals corresponding to the arguments are listed, and the return status is zero. exit_status is a number specifying a signal number or the exit status of a process terminated by a signal.
The return status is true if at least one signal was successfully sent, or false if an error occurs or an invalid option is encountered.
Common Kill Signals Signal name Signal value Effect SIGHUP 1 Hangup SIGINT 2 Interrupt from keyboard SIGQUIT 3 Quit SIGABRT 6 Cancel SIGKILL 9 Kill signal SIGTERM 15 Termination signal - allow an orderly shutdown SIGSTOP 17,19,23 Stop the process
This is a BASH shell builtin, to display your local syntax from the bash prompt type: help kill or man kill
List the running process
$ ps PID TTY TIME CMD 1293 pts/5 00:00:00 MyProgram
Then Kill it
$ kill 1293 + Terminated MyProgram
To run a command and then kill it after 5 seconds:
$ my_command & sleep 5
$ kill -0 $! && kill $!
kill is a bash built in command: $ help kill
“Whom the gods love dies young” - Menander 300 BC
Related linux commands:
ctrl+z - Suspend a program.
ctrl+c - Interrupt a program.
bg - Put a process in the background.
jobs - List your own processes (returns Job No.).
killall - kill processes by name.
pkill - Kill processes by a full or partial name.
ps - List running processes (returns PID).
Xkill - Kill a malfunctioning program by clicking on it's window.
Windows equivalent command: pskill- Stop a process from running.