R
Rookie
Hi,
I have a program that fork()'s + execlp()'s two children. Later in the
program I want to send a signal to the parent(SIGINT) . The parent's signal
handler should then send signals to these two children. I am able to catch
the signal in the parent - on catching this signal I invoke a function that
sends kill(childPid,SIGINT) but the signal handler in the child doesn't
seem to be getting invoked. Can someone please tell me why this is
happenning? Since this is kind of urgent I would greatly appreciate a speedy
response. Thanks a lot!
I am including the code below - first the parent's and following that the
child's
Parent code:
void sendKillsToChildren()
{
int i;
for(i=0;i<nNValue;i++)
{
printf("sending kil to %d\n",childPids);
kill(childPids,SIGINT);
}
}
void signalHandler(int dud)
{
printf("ctrl-c pressed\n");
printf("sendKillsToChildren\n");
sendKillsToChildren();
}
int main()
{
signal(SIGINT,signalHandler);
int i;
childPids=(int*)malloc(nNValue*sizeof(pid_t));
for(i=0;i<2;i++)
{
switch(childPids=fork())
{
case -1:
//Error
perror("Error in fork() in godclass::forkOne()");
break;
case 0:
//In Child
execlp("child.o",0);
break;
default:
//In parent
printf("child[%d]=%d\n",i,childPids);
break;
}
}
while(1);
}
Child code:
void signalHandler(int dud)
{
printf("recvd signal in %d\n",getpid());
}
int main()
{
signal(SIGINT,signalHandler);
printf("in child process %d\n",getpid());
}
I have a program that fork()'s + execlp()'s two children. Later in the
program I want to send a signal to the parent(SIGINT) . The parent's signal
handler should then send signals to these two children. I am able to catch
the signal in the parent - on catching this signal I invoke a function that
sends kill(childPid,SIGINT) but the signal handler in the child doesn't
seem to be getting invoked. Can someone please tell me why this is
happenning? Since this is kind of urgent I would greatly appreciate a speedy
response. Thanks a lot!
I am including the code below - first the parent's and following that the
child's
Parent code:
void sendKillsToChildren()
{
int i;
for(i=0;i<nNValue;i++)
{
printf("sending kil to %d\n",childPids);
kill(childPids,SIGINT);
}
}
void signalHandler(int dud)
{
printf("ctrl-c pressed\n");
printf("sendKillsToChildren\n");
sendKillsToChildren();
}
int main()
{
signal(SIGINT,signalHandler);
int i;
childPids=(int*)malloc(nNValue*sizeof(pid_t));
for(i=0;i<2;i++)
{
switch(childPids=fork())
{
case -1:
//Error
perror("Error in fork() in godclass::forkOne()");
break;
case 0:
//In Child
execlp("child.o",0);
break;
default:
//In parent
printf("child[%d]=%d\n",i,childPids);
break;
}
}
while(1);
}
Child code:
void signalHandler(int dud)
{
printf("recvd signal in %d\n",getpid());
}
int main()
{
signal(SIGINT,signalHandler);
printf("in child process %d\n",getpid());
}