in reply to Re: Re: Re: Re: Re: Re: Re: Re: Passing function to a function using \&<function name> method
in thread Passing function to a function using \&<function name> method
What happens is that there are two processes running from the exec line and the kill will only kill of the parent of the two processes.
I don't know why a redirection would create 2 processes, but if I wanted to get the output of the child, I would just spawn a child with a filehandle attached, and read it from the parent. I would change the spawn function as follows. WARNING: I haven't tested this at all):
sub spawn { my ($timeout, @cmd) = @_; defined( my $child_pid = open(CHILD_OUTPUT, "-|" ) or die "fork: $!"; if ($child_pid) { # parent eval { local $SIG{ALRM} = sub { timeout($child_pid); }; alarm $timeout; while (<CHILD_OUTPUT>) { # log it } close(CHILD_OUTPUT) or warn "process $child_pid exited: $? +"; alarm 0; }; if ($@) { print "oops: $@"; } } else { # child exec @cmd or die "exec: $!"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Passing function to a function using \&<function name> method
by Anonymous Monk on Mar 18, 2004 at 21:29 UTC | |
by rich_d_thomas (Sexton) on Apr 03, 2004 at 13:02 UTC |