I have some very basic code, here that creates two NAMED pipes, one for a handler and another for an execuetor.
Now I have a partially implemented signal handler, that handles signals from the pipes
How would I go about refactoring this to use epoll instead of traditional signal handlers.
Do I need signal handlers if I have used epoll?
void exchange_signal_handler(int signo);
int main(int argc, char ** argv) {
if (argc < 2) {
printf("Not enough arguments\n");
return 1;
}
char handler[100];
char exec[100];
sprintf(handler, "/tmp/handler_%s", argv[1]);
sprintf(exec, "/tmp/execuetor_%s", argv[1]);
int fd1 = open(handler,O_RDWR);
int fd2 = open(exec,O_RDWR);
if (signal(SIGINT, exchange_signal_handler) == SIG_ERR) {
printf("Unable to register exchange signal handler\n");
return 1;
}
}
void exchange_signal_handler(int signo) {
printf("Received signal %d from exchange with data: %s\n", signo);
}
For example, how would I refactor so that my code uses the epoll api, to listen for SIGUSR1 signal from the handler. And then write a message (lets say "Hello World") to the exec pipe after a SIGUSR1 is received from handler?