[URGENT]Signal Handling
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > [URGENT]Signal Handling




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    [URGENT]Signal Handling  
Rookie


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 01:48 AM

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[i],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[i]);
kill(childPids[i],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(pi
d_t));

for(i=0;i<2;i++)
{
switch(childPids[i]=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[i]);
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());
}








[ Post a follow-up to this message ]



    Re: [URGENT]Signal Handling  
Walter Roberson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 01:48 AM

In article <cl15qm$pd7$1@gist.usc.edu>,
Rookie <dominicjoseph@rediffmail.com> wrote:
: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.

:int main()
:{
: signal(SIGINT,signalHandler);

:  switch(childPids[i]=fork())

:   execlp("child.o",0);


I have not looked closely to see what the source of your problem is,
but I do notice that you are not taking any particular care to
ensure that the children are not in the same process group as
the main process. Is it possible that the same signal is going to
all members of the same process group, not just to the main
process?
--
If a troll and a half can hook a reader and a half in a posting and a half,
how many readers can six trolls hook in six postings?





[ Post a follow-up to this message ]



    Re: [URGENT]Signal Handling  
all mail refused


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 01:48 AM

In article <cl15qm$pd7$1@gist.usc.edu>, Rookie wrote:

>int main()
>{
> signal(SIGINT,signalHandler);
> int i;

You can't have declarations after code in a function.
These are not complete programs with headers and all.

>   //In Child
>   execlp("child.o",0);

This looks fishy - are you sure you're successfully executing
a real program ?  There's nothing to catch an execlp() failure.

You attempt to signal an entire arrayful of pids rather than
just the ones that have been used.

Most critically are you sure your child hasn't exited anyway
as
int main() {
signal(SIGINT,signalHandler);
printf("in child process %d\n",getpid());
}
contains no delay loop.  Test the child's response to a signal
direct from the command-line.

I prefer my while(1) delay loops to contain a sleep().

With all of the above corrected, and on Linux it works.

--
Elvis Notargiacomo  master AT barefaced DOT cheek
http://www.notatla.org.uk/goen/
7.031: OnACPower returned value( 0x1 ) which is Equal To 0x1





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:33 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register