Hi,
I'm trying to create this program that does nothing until it's interrupted in the child, if the interrupt occurs then the parent should sent a SIGQUIT, so fare i have been stuck in an infinite loop =/
Any help is appreciated
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int NumberOfInterrupts;
void InterruptCatcher(int Signal)
{
NumberOfInterrupts++;
}
void QuitFunction(int Signal)
{
printf("Goodbye\n");
}
int main(void)
{
int ChildID;
NumberOfInterrupts=0;
void (*Response)(int);
if((Response=signal(SIGINT,InterruptCatcher))==SIG_ERR)
{
perror("Interrupt");
return(EXIT_FAILURE);
}
if((ChildID=fork())==-1)
perror("fork");
/*in the child process wait for an interrupt*/
if(ChildID==0)
{
while(NumberOfInterrupts<1)
{
printf("Inside loop\n");
sleep(2);
}
}
/*int the parent process SIGQUIT*/
if((Response=signal(SIGQUIT,QuitFunction))==SIG_ERR)
{
perror("error");
return(EXIT_FAILURE);
}
return 0;
}