Skip to content

Instantly share code, notes, and snippets.

@eregon
Created April 27, 2017 14:28
Show Gist options
  • Save eregon/62229815950767c8ab8a91c20e47e403 to your computer and use it in GitHub Desktop.
Save eregon/62229815950767c8ab8a91c20e47e403 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
void on_signal(int sig) {
printf("\nIN handler\n");
//nothing
}
int main(int argc, char const *argv[])
{
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = on_signal;
// no SA_RESTART here
// act.sa_flags = SA_RESTART;
if (sigaction(SIGINT, &act, NULL) < 0) {
perror("sigaction");
return 1;
}
while (1) {
char c;
int ret = read(STDIN_FILENO, &c, 1);
printf("%d: >%c<\n", ret, c);
if (ret == 0) {
break;
} else if (ret == -1) {
printf("IS EINTR: %d\n", errno == EINTR);
perror("read");
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment