Medium
A signal arriving during a blocking read()
The process is blocked inside read(), waiting on stdin with no data available yet. A signal arrives for which a handler was installed via sigaction() without SA_RESTART. The handler runs and returns. What does the interrupted read() call do?
main.cpp
#include <unistd.h>
#include <cerrno>
#include <cstdio>
int main() {
char buf[64];
ssize_t n = read(0, buf, sizeof(buf));
if (n < 0) {
printf("read failed, errno=%d\n", errno);
} else {
printf("read %zd bytes\n", n);
}
return 0;
}9 of 53 in Operating Systems