I read about EINTR on write(2) etc. and trying to determine if I need to check it in my program. As a test for performance, I tried to write a program that will work in it. Loop program forever by repeatedly repeating a file.
Then in a separate shell I run:
while true; do pkill -HUP test; done
However, the only conclusion I can see from test.c is this . from the signal handler. Why isn't SIGHUP calling write(2) called?
test.c:
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <signal.h> #include <string.h> #include <errno.h> #include <sys/types.h> void hup_handler(int sig) { printf("."); fflush(stdout); } int main() { struct sigaction act; act.sa_handler = hup_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGHUP, &act, NULL); int fd = open("testfile", O_WRONLY); char* buf = malloc(1024*1024*128); for (;;) { if (lseek(fd, 0, SEEK_SET) == -1) { printf("lseek failed: %s\n", strerror(errno)); } if (write(fd, buf, sizeof(buf)) != sizeof(buf)) { printf("write failed: %s\n", strerror(errno)); } } }
source share