Skip to content

Instantly share code, notes, and snippets.

@jul
Created November 1, 2012 16:01
Show Gist options
  • Select an option

  • Save jul/3994570 to your computer and use it in GitHub Desktop.

Select an option

Save jul/3994570 to your computer and use it in GitHub Desktop.
signal in C
#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