LPIC-1 Shells, Scripting and Data Management Practice Question
A script running as a daemon should perform clean-up operations when it receives SIGTERM. Which command inside the script sets up this behavior?
⚠ Common exam trap
Candidates often confuse signal names with signal numbers or mix up SIGTERM (15, catchable) with SIGKILL (9, uncatchable), or they incorrectly assume the EXIT pseudo-signal is equivalent to SIGTERM, when in fact EXIT triggers on any script termination, not specifically on a SIGTERM request.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
trap 'cleanup' SIGTERM
The `trap` command in Bash allows a script to catch signals and execute specified commands. The syntax `trap 'cleanup' SIGTERM` registers the `cleanup` function or command to run when the SIGTERM signal (signal 15) is received, which is the standard signal sent by `systemctl stop` or `kill` to request graceful termination of a daemon. This ensures the daemon performs clean-up operations before exiting.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
trap cleanup TERM
Why it's wrong here
Missing quotes; cleanup may be interpreted as variable expansion.
- ✓
trap 'cleanup' SIGTERM
Why this is correct
Sets a trap for SIGTERM to run the cleanup function.
- ✗
trap 'cleanup' EXIT
Why it's wrong here
Runs cleanup on any exit, not specifically SIGTERM.
- ✗
trap "cleanup" 9
Why it's wrong here
Signal 9 is SIGKILL, which cannot be caught or ignored.
Go deeper
Related to this question
About these practice questions
One of 527 original LPIC-1 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This LPIC-1 practice question is part of Courseiva's free LPI certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LPIC-1 exam.