Created
November 1, 2012 16:01
-
-
Save jul/3994570 to your computer and use it in GitHub Desktop.
signal in C
This file contains hidden or 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 <signal.h> | |
| #include <unistd.h> | |
| #include <stdio.h> | |
| #include <fcntl.h> | |
| #include <errno.h> | |
| #include <bits/signum.h> | |
| int val=0; | |
| int pipefd[2]; | |
| #define RPIPE 0 | |
| #define WPIPE 1 | |
| void send_sig(int signal) { | |
| write(pipefd[WPIPE], &signal, 1); | |
| } | |
| int main(void) { | |
| int signal_received=0; | |
| printf("hello word\n"); | |
| pipe(pipefd); | |
| fcntl(pipefd[RPIPE],F_SETFD, O_NONBLOCK); | |
| fcntl(pipefd[WPIPE],F_SETFD, O_NONBLOCK); | |
| signal(SIGHUP,send_sig); | |
| signal(SIGUSR1,send_sig); | |
| for(;;) { | |
| printf("%s","processing\0"); | |
| char buf[1]; | |
| while(read(pipefd[RPIPE],buf,1) !=0 || errno != EINTR){ | |
| printf("received sig; (%d)%d\n",signal_received++, (int )*buf); | |
| printf("E:%d\n", errno); | |
| } | |
| pause(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment