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;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.