AI Hints
Home›Linux Tutorial›Stopping Processes
Linux · Lesson 82 of 120

kill: Stopping Processes

Signals.

⏱ 2 min read▶ Video at 1:49:08🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Sometimes a program freezes, or runs forever, and control C can't reach it, because it's not in your terminal. Then you need to stop it by its PID. That's what kill does.

kill: Stopping Processes
From the video: kill: Stopping Processes
  • A program won't stop
  • Ctrl+C can't reach it
  • kill it by its PID

Find it, then kill it

First, find the PID. P grep backup prints the PID of anything called backup. Then kill, and that number, asks it to stop. P grep again finds nothing. The backup script is gone.

Terminal
pgrep backup
21
kill $(pgrep backup)
pgrep backup || echo "not running"
not running

Signals

Kill doesn't really kill. It sends a signal, a small message. The default is term, which politely asks the program to finish, and clean up. Kill dash nine sends kill, which stops it instantly, with no chance to clean up. Use it only when the polite way fails. Control C sends a signal too, called int.

SignalNumberMeaning
TERM15please stop (default)
KILL9stop now, no clean up
INT2what Ctrl + C sends
HUP1reload, or the terminal closed

Kill by name

Typing PIDs gets tiring. P kill stops processes by name, and kill all does something similar. Be careful, though. A short name might match more than you expect. P grep dash L first shows what would be matched, with names.

keyvalue
kill PIDpolite stop
kill -9 PIDforced stop
pkill namestop by name
pgrep -l namecheck first

Summary

Kill sends a signal to a process. The default asks it to stop, and dash nine forces it. P grep finds PIDs, and P kill stops by name. Next, services, the programs that run all the time.

Key takeaways
  • pgrep name
  • kill PID
  • kill -9 PID
Next up: Services — programs that run all the time