#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include "utils.h"
void do_something(int signal)
{
printf("signal: %d\n", signal);
}
int main(int argc, char *argv[])
{
struct sigaction sa = {
sa.sa_handler = do_something,
sa.sa_flags = 0,
};
sigemptyset(&sa.sa_mask);
printf("pid: %d\n", getpid());
exit_if(
sigaction(SIGUSR1, &sa, NULL) == -1,
"Can't install sig handler");
exit_if(sigaction(SIGUSR2, &sa, NULL) == -1,
"Can't install sig handler");
#ifndef PIPE_EXEMPLE
while(1)
sleep(1);
#else
char buffer[100];
int r;
while((r = read(STDIN_FILENO, buffer, sizeof(buffer))) != 0) {
if (r == -1 && errno == EINTR) continue;
exit_if(write(STDOUT_FILENO, buffer, r) == -1, "Can't write");
}
#endif
printf("good bye\n");
return 0;
}