Beginner · Processes, services and logs · topic 14 of 57 · 25 min
Signals, kill and process priority
Explanation
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.
| Signal | Number | Usual meaning | Sent by |
|---|---|---|---|
| SIGHUP | 1 | Hang-up; many services reload their config | kill -HUP, closing a terminal |
| SIGINT | 2 | Interrupt | Ctrl+C |
| SIGKILL | 9 | Kill now; cannot be caught or ignored | kill -9 |
| SIGTERM | 15 | Please terminate cleanly (the default) | kill PID |
| SIGCONT | 18 | Continue a stopped process | kill -CONT, fg, bg |
| SIGSTOP | 19 | Pause; cannot be caught | kill -STOP |
| SIGTSTP | 20 | Pause request from the keyboard | Ctrl+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
$ 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 startupsFor 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.
$ 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 prioritynice 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
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.
# 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 19Practice (0/3 done)
Which signal does plain "kill 1234" send?
Which process will get the MOST CPU time when the CPU is busy?
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
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- systemd services and systemctlProcesses, services and logs · same module
- Targets: the boot goal of the systemProcesses, services and logs · same module
- Processes, signals and systemd servicesDevOps: Git, Docker, Kubernetes and CI/CD · Linux for DevOps
- Configuration, project structure and graceful shutdownGo Programming (backend and cloud) · Building a REST API with a database
- set, stack, queue, deque and priority_queueC++ Programming (modern C++ and DSA) · The Standard Template Library (STL)
- Heaps and priority queuesData Structures and Algorithms (DSA) for interviews · Heaps and greedy algorithms
Questions people ask about this
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.
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.
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.
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.
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
- 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.
- Module 3 exam: Processes, services and logs · 14 questions · 25 min, without help. 6 topics of this module still to finish first.
- Then the next module, Software and networking. 57 topics left in the course before the final exam.