Unix signals
The SIGHUP, SIGINT, SIGQUIT, SIGKILL, SIGSEGV, SIGTERM, SIGCHLD, SIGCONT, SIGSTOP and SIGTSTP signals: who sends them, what they do by default, which ones a program can catch, and the kill, killall and pkill commands.
- 28 cards
- 4 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
A few cards from the deck
Signal: what is it?
Show the answer
A very short message, identified by a number and a name, sent by the kernel or by another process to warn or interrupt a process.
The process can usually catch it and react in its own way, ignore it, or undergo the default action. Two signals escape this: SIGKILL and SIGSTOP.
What does the command
kill 4242do?- Sends SIGTERM to process 4242, which can catch it
- Sends SIGKILL to process 4242: immediate stop, no appeal
- Sends SIGINT to process 4242, like Ctrl+C in its terminal
- Sends SIGHUP to process 4242 to make it reread its configuration
Show the answer
Sends SIGTERM to process 4242, which can catch it
With no option, kill sends SIGTERM (15). The word kill suggests a forced stop, but it is a request: the program keeps control so it can end cleanly.
… suspends a process without it being able to oppose, and … makes it resume where it had stopped.
Show the answer
SIGSTOP suspends a process without it being able to oppose, and SIGCONT makes it resume where it had stopped.
SIGTSTP, sent by Ctrl+Z, does the same but a program can catch it. SIGSTOP cannot be caught, like SIGKILL.
SIGTERM (15): what is it?
Show the answer
A polite request to stop: the program can catch it to finish its writes and close its files before leaving.
It is the signal sent by kill with no option. Service managers send this one first, then SIGKILL if the process does not leave.
kill 4242seems to do nothing and the service is still writing to its database. What should you do?- Let it finish, watch it with ps, and move to SIGKILL only as a last resort
- Send kill -9 right away: a service that is still writing must have ignored SIGTERM
- Send kill 4242 several more times: each SIGTERM received speeds up the stop
- Treat the process as a zombie, which kill -9 removes immediately
Show the answer
Let it finish, watch it with ps, and move to SIGKILL only as a last resort
SIGTERM was received: the service finishes its writes before stopping, which is exactly what you want to let it do. SIGKILL could leave the database in an inconsistent state.