On Dec 8, 2003, at 5:10 PM, [EMAIL PROTECTED] wrote:


On Tue, Dec 09, 2003 at 01:04:01AM +0100, [EMAIL PROTECTED] wrote:
eval {
  local $SIG{ALRM} = sub { die "alarm\n" };
  alarm 10;
  system($prog, @args);
  alarm 0;
};
if($@ =~ /alarm/) {
  # have to kill $prog;
    # I tried with 'use POSIX qw/sys_wait_h/;'
    my $kid = waitpid -1, WNOHANG;
    print "$kid\n";
    kill 15, $kid;
}


But this doesn't work, because waitpid returns 0 while the child
is running.

that waitpid() has the problem that it is WAITING for the process to exit, which is not what you will want.

let's pause for a moment, and go back to the POD,

system PROGRAM LIST
Does exactly the same thing as "exec LIST", except that a fork
is done first, and the parent process waits for the child pro-
cess to complete.


so what you are trying for is a BIT MESSY.

plan A: since you know that $$ is your pid,
all you would need to do is look for all of
the child processes of it.

plan B: go with some sort of traditional
fork solution where you collect the
the pid on the parent side.

eg:
        if ( !( $pid = fork()))
        {
                # Traditionally this is where we would exec the command
                exec(" $CMD 2>&1");
                exit;
        }
        #
        # parent side
        #

where you now set up your alarm() and pid_killer,
since YOU have that PID in your hand...

a more grotesque version of this is up at:

<http://www.wetware.com/drieux/pbl/Sys/gen_sym_big_dog.txt>



ciao
drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to