The four lines that install a reliable handler
The four lines that install a reliable handler
Answer
struct sigaction sa; sa.sa_handler = on_int; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; if (sigaction(SIGINT, &sa, NULL) == -1) _exit(1);
Memorise this shape — it is the body of the A3 Q3 answer. sa_handler is the disposition, sigemptyset clears the extra block set (never skip it), SA_RESTART resumes an interrupted slow call, and sigaction returns -1 on failure.
POSIX.1-2024 (IEEE Std 1003.1-2024) — sigaction(), <signal.h>, and the async-signal-safe function list; sigaction(2)