What each signal means: TERM, KILL, HUP, STOP and CONT

Video 123 of 140 in Virtualization Foundations, in the unit “Processes, signals, /proc and /sys”. 4:06, with English and Hindi audio.

To stop, pause or reload a running program, you send it a signal. A signal is a short numbered message that the kernel delivers to a process, and the process decides how to react. Five signals cover most of the work: TERM, KILL, HUP, STOP and CONT. Each one asks for something different, and only some of them can be caught or ignored. This article explains each signal, how to send one with kill, and what can go wrong with each.

What you will learn

A message sent to a running program

Suppose a stock report is running on a warehouse server, and it must stop. You cannot reach into its memory and switch it off. Instead, you send a signal. A signal is a short message that the kernel delivers to a process. It has a name, such as TERM, and a number, such as fifteen.

You send the signal with the kill command, naming the signal and the process ID. The name kill is misleading, because the command can also pause a process or ask it to reload.

How the five signals differ

TERM is the polite request, and a program can catch it, save its work and leave. KILL and STOP are the two that a program cannot catch. KILL ends the process, and STOP only pauses it.

Sending signals from the command line

List every signal by name and number
kill -l

The list is long, so start with the first few lines, which show HUP, INT and QUIT. Name the signal after a dash, followed by the process ID. A plain TERM is the default, so kill with only the ID sends TERM. kill prints nothing when the signal is delivered.

Ask process 4312 to stop politely
kill -TERM 4312
Ask process 4312 to reload its settings
kill -HUP 4312

Note: HUP asks the program to reload its settings, if it is written to do that.

Pause process 4312
kill -STOP 4312
Let process 4312 continue from the same point
kill -CONT 4312

What goes wrong with signals

The main risk of KILL is that the program never gets to clean up. Files can be left half written, and lock files can stay behind. HUP does not always mean reload. Some programs simply exit when they receive it, so check what the program does before you send it.

A stopped process still holds its memory and its open files. Other work can stay blocked until you continue it or end it.

Try it yourself

Use a process that you own and may stop or restart, and replace 4312 with its process ID. Some programs exit on HUP instead of reloading, so pick one you can start again.

  1. List every signal by name and number. Start with the first few lines.

    kill -l

    What you should see: The list starts with HUP, INT and QUIT.

  2. Ask the process to stop politely. kill prints nothing when the signal is delivered.

    kill -TERM 4312

    What you should see: kill prints nothing. A program that handles TERM begins to save its work and exit.

  3. Ask the process to reload its settings. This works only if the program is written to reload on HUP.

    kill -HUP 4312

    What you should see: If the program reloads on HUP, it keeps running and applies its new settings. Otherwise it may exit.

  4. Pause the process. It keeps its memory and uses no CPU while paused.

    kill -STOP 4312
  5. Let the paused process continue from the same point.

    kill -CONT 4312

    What you should see: The process carries on from the point where it stopped.

Terms

Signal
A short numbered message from the kernel, or from a user, to a process. Each signal has a name and a number.
Hangup (HUP)
The signal that says a terminal went away, which many services also read as a request to reload their settings.

Check yourself

Which signal can a program catch and use to save its work?

TERM. It asks the program to finish and clean up, and a well-written program can save its work before it leaves.

Why is KILL the risky choice?

KILL ends the process at once, and the program cannot clean up. Files can be left half written, and lock files can stay behind.

What does STOP do, and how is it undone?

STOP pauses the process and keeps its memory. CONT resumes it from the same point.

Previous: Watching live load with top and htop. Next: Killing a process safely.