linux-sysprog · beginner · ~15 min

Can the signal be caught?

Know the two uncatchable signals.

Challenge

Almost every signal can be caught by a handler — except two that the kernel reserves so a process can always be killed or paused. Identify whether a signal is catchable.

Task

Implement int is_catchable(int sig) that returns 1 if sig can be caught or ignored, else 0.

Input

  • sig: a signal number (compare against the <signal.h> constants).

Output

0 for SIGKILL and SIGSTOP; 1 for any other signal.

Example

is_catchable(SIGINT)    ->   1
is_catchable(SIGKILL)   ->   0
is_catchable(SIGSTOP)   ->   0

Edge cases

  • Only SIGKILL and SIGSTOP are uncatchable.

Input format

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

Output format

0 for SIGKILL/SIGSTOP, else 1.

Constraints

Match by the signal.h constants.

Starter code

#include <signal.h>

int is_catchable(int sig) {
    /* TODO */
    return 1;
}

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