EX200 Essential Tools Practice Question
An administrator wants to ensure that when a user presses Ctrl+C during a long-running script, the script cleans up temporary files before exiting. Which approach should the script use?
⚠ Common exam trap
Red Hat often tests the distinction between signals like SIGINT (Ctrl+C) and EOF (Ctrl+D), leading candidates to confuse `ignoreeof` with signal handling.
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
✓
Use 'trap' to catch SIGINT and run cleanup.
The `trap` command in Bash allows a script to catch signals like SIGINT (sent when Ctrl+C is pressed) and execute a custom function or command before exiting. By setting `trap cleanup SIGINT`, the script can remove temporary files or perform other cleanup actions automatically, ensuring a graceful termination.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Use 'trap' to catch SIGINT and run cleanup.
Why this is correct
The `trap` built-in lets the script register a custom handler for signals such as SIGINT, which is what pressing Ctrl+C sends. When the signal is received, the shell suspends the current operation and runs the specified cleanup routine, allowing the administrator to remove temporary files, release locks, or log the interruption before exiting. Setting `trap cleanup INT` (or using a quoted command list) is the standard way to gracefully intercept an interrupt and maintain controlled state.
- ✗
Use 'set -o ignoreeof' to ignore Ctrl+C.
Why it's wrong here
`set -o ignoreeof` only affects the end-of-file character (Ctrl+D), causing the shell to ignore EOF input so an accidentally typed Ctrl+D does not log out an interactive shell. Ctrl+C, however, transmits SIGINT to the foreground process group, which is an entirely distinct mechanism and is not influenced by the EOF setting. Because the administrator needs to handle the SIGINT signal, `ignoreeof` cannot prevent or handle Ctrl+C and therefore would not run any cleanup.
- ✗
Run the script in the background with '&'.
Why it's wrong here
Running the script in the background with `&` starts it as an asynchronous subshell and immediately returns control to the calling shell, but it does not install any signal handler. Under normal job control, a background job is not part of the foreground process group, so pressing Ctrl+C sends SIGINT only to the foreground group; the background script may never receive the signal, and if it does, the default action is immediate termination without cleanup. Thus backgrounding neither catches the interrupt nor provides an opportunity for the administrator's cleanup logic to execute.
- ✗
Use 'set -e' to exit on any error.
Why it's wrong here
`set -e` instructs the shell to exit immediately whenever a command, pipeline, or list returns a non-zero exit status, serving only as an error-handling mechanism for command failures. It has no role in signal delivery: pressing Ctrl+C still sends SIGINT to the shell and its children, and the script terminates according to the default signal disposition rather than running a cleanup routine. Moreover, `set -e` gives the administrator no way to define what actions should happen when an interrupt arrives, so it cannot ensure cleanup on Ctrl+C.
Go deeper
Related to this question
About these practice questions
Courseiva writes every EX200 question from scratch — 427 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This EX200 practice question is part of Courseiva's free Red Hat 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 EX200 exam.