How can I get if a process receives a signal? The purpose of the following example is to fork a process, read a character with the child process and send SIGUSR1 to parent, but if after 10 seconds the user still have to insert the character, the child process is terminated. The question is how to know if SIGUSR1 is received:
#define _POSIX_SOURCE
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
void handle_USR1()
{
return;
}
int main(void)
{
int p[2];
pid_t pid;
if(pipe(p) == -1)
{
perror("pipe");
return -1;
}
if((pid = fork()) == -1)
{
perror("fork");
return -1;
}
if(pid == 0)
{
close(p[0]);
char ch, b;
ch = getchar();
if(ch != '\n')
while((b = getchar()) != '\n' && b != EOF);
write(p[1], &ch, 1);
kill(getppid(),SIGUSR1);
exit(-1);
}
else
{
signal(SIGUSR1,handle_USR1);
close(p[1]);
char ch;
sleep(10);
kill(pid, SIGTERM);
read(p[0],&ch,1);
//if(/*SIGUSR1 is not recived*/)
//{
// exit(-1);
//}
printf("\n\n%c",ch);
}
return 0;
}
What can I replace /*SIGUSR1 is not recived*/
with?