The kill command
The kill command sends a signal to a process, usually to stop it…
The kill command sends a signal to a process, usually to stop it: kill 1234 asks process 1234 to end, and kill -9 1234 forces it.
Taught in Intermediate, lesson 26; more in Ninja
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.
Usage
kill [-SIGNAL] PID|%JOB... kill -l
Send a signal to a process (usually: stop it). Sends a signal to each process ID (from ps, pgrep or $!) or job (%1 from jobs). The default, TERM (15), asks the program to stop and lets it clean up. KILL (9) ends it at once and can’t be ignored; use it only when TERM doesn’t work. HUP (1) often makes a service reload its settings; STOP and CONT pause and resume. You can only signal your own processes, unless you use sudo.
In the practice terminal:The processes and signals are simulated inside the page; nothing on your own computer is touched.
How to use kill
Stop a process by its PID
Find the PID with ps or pgrep, then kill it. Here $! holds the PID of the job just started with &.
sleep 600 & kill $![1] 5000 [1]+ Terminated sleep 600
Stop a background job: kill %1
%1 is job 1 in the jobs list, so you don’t need its PID.
sleep 600 & kill %1[1] 5000 [1]+ Terminated sleep 600
Force it: kill -9
Plain kill sends TERM, a polite request the program can catch to tidy up first. -9 (KILL) can’t be caught or ignored, so keep it for a program that won’t stop otherwise.
sleep 600 & kill -9 %1[1] 5000 [1]+ Killed sleep 600
Pause and resume: kill -STOP, kill -CONT
-STOP freezes a process without ending it, as Ctrl+Z does; -CONT lets it carry on.
sleep 600 & kill -STOP %1; jobs[1] 5000 [1]+ Stopped sleep 600
Stop by name: pkill and killall
pkill matches part of the name and killall the exact name. Check what would match with pgrep -l first.
sleep 600 & pkill sleep[1] 5000 [1]+ Terminated sleep 600
Options
| -9, -KILL | end it now |
|---|---|
| -15, -TERM | ask it to stop (the default) |
| -STOP, -CONT | pause it, resume it |
| -s NAME | the signal by name |
| -l | list the signals |
More examples
sleep 600 &[1] 5000
kill %1[1]+ Terminated sleep 600
kill -l1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU
Questions about kill
What is the difference between kill and kill -9?
kill sends SIGTERM (15), which asks the program to finish and lets it save its work. kill -9 sends SIGKILL, which the system carries out at once, so the program gets no chance to clean up.
Why does kill say "Operation not permitted"?
The process belongs to another user, such as root. Only its owner or root may signal it, so use sudo kill PID if you are sure.
Does kill only stop processes?
No, it sends any signal. HUP often tells a server to reload its settings, and STOP and CONT pause and resume a process. Stopping is just the most common use.
Learn it step by step
Related commands
Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.