linux-sysprog · intermediate · ~15 min
Recall which signals kill by default.
Each signal has a default action; for many it is to terminate the process. Classify a signal by its default action.
Implement int default_terminates(int sig) that returns 1 if sig's default action terminates the process, else 0.
sig: a signal number (compare against the <signal.h> constants).1 for SIGINT, SIGTERM, SIGKILL, SIGQUIT, SIGSEGV; else 0.
default_terminates(SIGINT) -> 1
default_terminates(SIGKILL) -> 1
default_terminates(SIGCHLD) -> 0 (ignored by default)
sig: a signal number from <signal.h>.
1 for SIGINT/SIGTERM/SIGKILL/SIGQUIT/SIGSEGV, else 0.
Match by the signal.h constants.
#include <signal.h>
int default_terminates(int sig) {
/* TODO */
return 0;
}
Calling non-reentrant functions (like printf or malloc) inside signal handlers; neglecting sig_atomic_t or volatile qualifier for shared flags.
Multiple instances of the same signal queued together; signal arriving while handler is already active; interrupted system calls (EINTR).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.