linux-sysprog · beginner · ~15 min

Is it a termination signal?

Group the process-ending signals.

Challenge

Some signals exist to end a process (Ctrl-C, kill, etc.). Classify a signal number as one of those.

Task

Implement int is_termination_signal(int sig) that returns 1 if sig is one of SIGINT, SIGTERM, SIGKILL, or SIGQUIT, else 0.

Input

  • sig: a signal number (compare against the signal.h constants, not raw numbers).

Output

1 for the four termination signals above, else 0.

Example

is_termination_signal(SIGTERM)   ->   1
is_termination_signal(SIGINT)    ->   1
is_termination_signal(SIGCONT)   ->   0

Edge cases

  • Non-terminating signals (e.g. SIGCONT, SIGUSR1): return 0.

Input format

sig: a signal number from <signal.h>.

Output format

1 for SIGINT/SIGTERM/SIGKILL/SIGQUIT, else 0.

Constraints

Match by the signal.h constants, not hardcoded numbers.

Starter code

#include <signal.h>

int is_termination_signal(int sig) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.