sending a kill to child process

A

AdamKaye-Smith

Hello ,


I am trying to run a shell process from perl program and giving it a
time limit to run in.

To do this I use the perl function - alarm to set of a timer and when my
program gets the %SIG{ALRM} signal it initiates a kill which is sent to
all processes in the group ie kill 1 ,(-$$). This all works as expected.

The problem is that this also kills my main perl program.

I attempt to make the main perl program ignore the kill signal by doing
the following :

local $SIG{HUP} = 'IGNORE';


but when I do this the child process also ignores the kill signal

here is the test program:

#!/usr/bin/perl -w

$SIG{HUP} = 'DEFAULT';


eval {
local $SIG{HUP} = 'IGNORE';
local $SIG{ALRM} = sub { kill 1 , (-$$) ; print "got rid of
them\n"; };
alarm 6;
system ("sleep 30 ");
alarm 0;
};
$SIG{HUP} = 'DEFAULT';

print "going from here\n";



How can I get this program to time out the system called process,
without timing out the main perl program.

I am running this under Fedora Core 4 op sys.


At my wits end,


Adam
 
X

xhoster

AdamKaye-Smith said:
Hello ,

I am trying to run a shell process from perl program and giving it a
time limit to run in.

To do this I use the perl function - alarm to set of a timer and when my
program gets the %SIG{ALRM} signal it initiates a kill which is sent to
all processes in the group ie kill 1 ,(-$$). This all works as expected.

The problem is that this also kills my main perl program.

I attempt to make the main perl program ignore the kill signal by doing
the following :

local $SIG{HUP} = 'IGNORE';

but when I do this the child process also ignores the kill signal

The child process inherits the parents sig handlers.

here is the test program:

#!/usr/bin/perl -w

$SIG{HUP} = 'DEFAULT';

eval {
local $SIG{HUP} = 'IGNORE';
local $SIG{ALRM} = sub { kill 1 , (-$$) ; print "got rid of
them\n"; };

What if you put the local $SIG{HUP} = 'IGNORE'; inside the ALRM handler
sub?

Or just do a fork and exec, then the parent will have the exact pid
it needs for doing the kill.

Xho
 
A

AdamKaye-Smith

Put the IGNORE inside the ALRM handler and works beautifully.


Thank-you very much

Adam
 

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

Forum statistics

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

Latest Threads

Top