linux-sysprog · intermediate · ~15 min

Signal yourself with kill

Use kill() with your own PID.

Challenge

Implement int kill_self(void) that installs a SIGUSR1 handler (setting a flag) and uses kill(getpid(), SIGUSR1) to send itself the signal, returning the flag.

Starter code

#include <signal.h>
#include <unistd.h>

int kill_self(void) {
    /* TODO */
    return 0;
}

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