[URGENT]Signal Handling

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());
}
 
V

Victor Bazarov

Rookie said:
I have a program that fork()'s + execlp()'s two children.

fork()-ing and execlp()-ing are beyond the scope of a language newsgroup.
You need to ask in a newsgroup where these things are topical. Like an NG
dedicated to your OS.

V
 
R

Ron Natalie

Rookie said:
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.

Are you sure you issued the "signal" to catch the signal in the exec'd
program "cihld.o"? Signals set to be caught by functions (as opposed
to default (SIG_DFL) or ignore (SIG_IGN) are reset to the default action.
How can it catch a signal into a handler that doesn't exist any more.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top