Created
April 27, 2017 14:28
-
-
Save eregon/62229815950767c8ab8a91c20e47e403 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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