linux-sysprog · intermediate · ~15 min
Test a flag bit in the sigaction flags word.
sigaction's sa_flags word controls handler behaviour; the SA_RESTART bit makes interrupted slow syscalls resume instead of failing with EINTR. Test for it.
Implement int restarts_syscalls(int flags) that returns 1 if the SA_RESTART bit is set in flags, else 0.
flags: an sa_flags value (bitmask).1 if SA_RESTART is set, else 0.
restarts_syscalls(SA_RESTART) -> 1
restarts_syscalls(0) -> 0
flags: an sa_flags bitmask.
1 if the SA_RESTART bit is set, else 0.
flags is an int representing sa_flags in a struct sigaction.
#include <signal.h>
int restarts_syscalls(int flags) {
/* TODO */
return 0;
}
Using equality (flags == SA_RESTART) instead of bitwise AND (& SA_RESTART).
flags == 0, flags with SA_RESTART set among other bits, flags without SA_RESTART.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.