Skip to content

Beginner · Processes, services and logs · topic 14 of 57 · 25 min

Signals, kill and process priority

Explanation

A signal is a short message to a process. kill sends one: SIGTERM (15) asks politely to stop, SIGKILL (9) stops at once, SIGHUP (1) often means "reload your config". pkill and killall pick processes by name. nice and renice change priority from -20 (most favoured) to 19 (least).

What is a signal?

A signal is a tiny notification the kernel delivers to a process. The process can catch most signals and react: save its work, close files, then exit. Two signals cannot be caught: SIGKILL ends the process immediately, and SIGSTOP pauses it.

SignalNumberUsual meaningSent by
SIGHUP1Hang-up; many services reload their configkill -HUP, closing a terminal
SIGINT2InterruptCtrl+C
SIGKILL9Kill now; cannot be caught or ignoredkill -9
SIGTERM15Please terminate cleanly (the default)kill PID
SIGCONT18Continue a stopped processkill -CONT, fg, bg
SIGSTOP19Pause; cannot be caughtkill -STOP
SIGTSTP20Pause request from the keyboardCtrl+Z

The numbers above are for Linux on x86 and ARM. Names are safer than numbers in scripts: kill -TERM is clearer than kill -15. kill -l lists all signals.

Sending signals

bash
$ kill 9812                 # SIGTERM: please stop
$ kill -SIGTERM 9812         # the same, written out
$ kill -9 9812               # SIGKILL: only if it ignores TERM
$ pkill -u reports java      # by name, only processes of user reports
$ killall httpd              # every process named httpd
$ pkill -t pts/3             # everything on terminal pts/3 (log a user out)
$ pgrep -a sshd              # check before you pkill
842 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
Careful: Always try SIGTERM first and wait a few seconds. SIGKILL gives the program no chance to save data or remove lock files. Killing a database with -9 can leave it needing a long recovery. And never pkill with a pattern you have not first tested with pgrep: pkill ssh would also match sshd and drop everyone's connection.

For services managed by systemd, use systemctl stop or systemctl kill instead of kill. systemd knows all the processes of the service and will not restart it unexpectedly.

Priority: nice and renice

When several processes want the CPU, the scheduler gives more time to those with higher priority. The nice value is how you influence it. It goes from -20 (least nice to others, most CPU) to 19 (very nice, gives way). The default is 0. A normal user can only make their processes nicer (raise the number); only root can lower it below the current value.

bash
$ nice -n 10 tar -czf /backup/home.tgz /home     # start with nice 10
$ ps -o pid,ni,comm -p 7001
  PID  NI COMMAND
 7001  10 tar
# renice -n -5 -p 1301                            # root: give PID 1301 more priority
1301 (process ID) old priority 0, new priority -5
$ top     # the NI column shows the nice value; PR is the kernel priority

nice only matters when the CPU is busy. On an idle server a nice 19 job runs at full speed. It does not limit memory or disk use; for those, systemd resource controls (for example CPUQuota= or MemoryMax= in a unit) are the modern tool.

Common mistakes

  • Using kill -9 as the first choice. Use it only when TERM does not work.
  • Thinking a higher nice number means higher priority. It is the opposite: 19 is the lowest priority.
  • Trying renice -n -5 as a normal user and getting "Permission denied". Only root can lower the nice value.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Signals, kill and process priority · 1/7

Signals

A signal is a short message to a process, like stop, pause or reload.

Prefer a video by a teacher? Find free videos on “linux kill signals sigterm sigkill nice renice tutorial” on YouTube ↗

In real life: A nightly backup that slowed down IRCTC-scale traffic

A travel booking company in Delhi runs a large compression job every night. One night it overlapped with a burst of bookings, and the API servers became slow. The admin did not want to stop the backup, so she reniced it to 19. The booking API got the CPU back, and the backup still finished, just later. The next day she changed the cron job to start the backup with nice -n 19.

bash
# pgrep -a tar
22051 tar -czf /backup/db-2026-10-19.tgz /var/lib/pgsql
# renice -n 19 -p 22051
22051 (process ID) old priority 0, new priority 19

Practice (0/3 done)

Task 1 · Question

Which signal does plain "kill 1234" send?

Task 2 · Question

Which process will get the MOST CPU time when the CPU is busy?

Task 3 · Code · Python

Write can_renice(current, new, is_root) that returns True if the change is allowed. Rules: the new value must be between -20 and 19; root can set any value in that range; a normal user may only keep or raise the value (new >= current).

Quick quiz

Question 1

1.Which signal cannot be caught or ignored?

Question 2

2.What does Ctrl+C send to the foreground process?

Question 3

3.Why test with pgrep before pkill?

Question 4

4.A normal user runs renice -n -5 -p 4000 on their own process at nice 0. What happens?

Question 5

5.What is the best way to stop a systemd service?

Read more (free)

Before this, learn

This topic builds on these. If something here feels new, open them first.

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Which signal cannot be caught or ignored?

Answer: SIGKILL

SIGKILL (and SIGSTOP) cannot be caught.

What does Ctrl+C send to the foreground process?

Answer: SIGINT

Ctrl+C sends SIGINT (2).

Why test with pgrep before pkill?

Answer: To see exactly which processes the pattern matches

A loose pattern can match more than you expect.

A normal user runs renice -n -5 -p 4000 on their own process at nice 0. What happens?

Answer: Permission denied: only root can lower nice values

Users can only raise the nice value.

What is the best way to stop a systemd service?

Answer: systemctl stop name

systemctl stop stops all of the service's processes cleanly.

You started a service with systemctl start, but after a reboot it is not running. What did you forget?Related

Answer: systemctl enable

start runs it now; enable makes it start at boot.

From Processes, signals and systemd services

How do you get rid of zombie processes?Related

Answer: Fix or restart the parent process

Zombies are already dead; the parent must collect them.

From Processes: ps, top and jobs

What is the difference between restart and reload?Related

Answer: restart stops and starts; reload re-reads config without stopping, if supported

reload keeps the process and reloads its config; not every service supports it.

From systemd services and systemctl

Why use a new context for Shutdown instead of the signal context?Related

Answer: The signal context is already cancelled, so Shutdown would give up immediately

A fresh timeout context gives requests time to finish.

From Configuration, project structure and graceful shutdown

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 4 more topics in “Processes, services and logs” before its exam: systemd services and systemctl, Targets: the boot goal of the system, Logs: journalctl, rsyslog and a persistent journal, Tuning profiles with tuned, and time with chrony.
  2. Module 3 exam: Processes, services and logs · 14 questions · 25 min, without help. 6 topics of this module still to finish first.
  3. Then the next module, Software and networking. 57 topics left in the course before the final exam.

← Previous: Processes: ps, top and jobs