Stopping Processes
A signal is a short message to a process. kill sends SIGTERM, the signal that tells a process to stop.
Stop a job
kill %1 sends SIGTERM to job number 1. The job list names it once as Terminated.
$ sleep 300 &
$ kill %1
$ jobs
$ jobsList the signals
kill -l prints the signal names with their numbers. The list is long, so head shows the first ten lines.
$ kill -l | headStop it at once
kill -9 sends signal 9 to job number 1. The job list names it as Killed.
$ sleep 300 &
$ kill -9 %1
$ jobs
$ jobsExample
$ cd ~/practice
$ sleep 300 &
$ kill %1
$ jobs
$ kill -l | head -3Key points
- Use kill with a job number, like kill %1, to stop a job.
- Use kill -l to list the signal names.
- SIGKILL is signal 9. It stops a process at once.
- A signal is a short message, and kill is the command that sends one.
In this example, the first command moves into the practice folder. A sleep job starts in the background. kill %1 sends SIGTERM to the job. jobs names it once as Terminated. kill -l prints the signal names last. The list starts with SIGHUP and holds SIGTERM at number 15.
Note
Some processes ignore SIGTERM, and SIGKILL stops those.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does kill send to a process?