linux-sysprog · advanced · ~15 min

Count SIGUSR1 deliveries

Signal handler basics and the safe types/operations available inside one.

Challenge

Implement int count_sigusr1(int times) that installs a SIGUSR1 handler, raises SIGUSR1 times times (via raise(SIGUSR1)), then returns the handler invocation count. The counter must be volatile sig_atomic_t.

Starter code

#include <signal.h>

int count_sigusr1(int times) {
    /* TODO */
    return -1;
}

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