linux-sysprog · intermediate · ~15 min

Async-signal-safe function?

Recall which calls are legal inside a signal handler.

Challenge

Only async-signal-safe functions may be called from a handler. Implement int is_async_signal_safe(const char *fn) returning 1 for "write", "_exit", "signal", "kill", "read", and 0 for "printf", "malloc", "free".

Starter code

#include <string.h>

int is_async_signal_safe(const char *fn) {
    /* TODO */
    return 0;
}

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