How do you manage background processes and signals?
Assesses fundamental understanding of Shell & Bash conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
Bash can start, inspect and signal processes. Append & to run a job in the background and $! holds its PID. wait blocks until it finishes.
sleep 30 &
pid=$!
kill -TERM "$pid" # ask to stop, catchable
sleep 1
kill -KILL "$pid" # forced, cannot be caught
wait "$pid" 2>/dev/null || true
jobs -l
Useful signals are SIGTERM for graceful shutdown, SIGINT from Ctrl-C, SIGHUP for reload or terminal close, SIGKILL for force and SIGSTOP/SIGCONT to pause and resume. kill -l lists signal names and numbers.
Trap signals for cleanup with trap 'echo bye; exit' TERM INT. pkill and pgrep match by name, while kill 0 signals the whole process group. Prefer tracking PIDs over killall, because name matching can hit unrelated processes, and never kill a PID you did not start.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.