linux-sysprog · intermediate · ~15 min
Deliver a signal synchronously with raise().
raise() sends a signal to the current process; with a handler installed, the handler runs synchronously before raise() returns. Prove that round trip.
Implement int raise_and_flag(void) that installs a SIGUSR1 handler which sets a flag, calls raise(SIGUSR1), and returns the flag.
None.
1 — the flag set by the handler after the signal is delivered.
raise_and_flag() -> 1
raise().static volatile sig_atomic_t flag for the handler.None.
1 once the SIGUSR1 handler has run.
Install the handler before raise(); use a sig_atomic_t flag.
#include <signal.h>
int raise_and_flag(void) {
/* TODO: install handler, raise(SIGUSR1), return the flag */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.