linux-sysprog · beginner · ~15 min

Is it a stop signal?

Identify the job-control stop signals.

Challenge

Job control uses stop signals to pause a process rather than kill it. Identify them.

Task

Implement int is_stop_signal(int sig) that returns 1 if sig is SIGSTOP or SIGTSTP, else 0.

Input

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

Output

1 for SIGSTOP or SIGTSTP, else 0.

Example

is_stop_signal(SIGSTOP)   ->   1
is_stop_signal(SIGTSTP)   ->   1   (Ctrl-Z)
is_stop_signal(SIGINT)    ->   0

Edge cases

  • Non-stop signals (e.g. SIGINT): return 0.

Input format

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

Output format

1 for SIGSTOP/SIGTSTP, else 0.

Constraints

Match by the signal.h constants.

Starter code

#include <signal.h>

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

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