At 2:16 PM -0500 1/12/05, Thomas R Wyant_III wrote:
>All,
>
>I have a need to spawn a command from a Perl script, time it out, and kill
>it if the timeout occurs. Under Perl 5.6.1, something like the following
>worked:
>
>$| = 1;
>my $cmd = "whatever comand I want to issue";
>my $tmot = 30;  # Timeout in seconds.
>my $pipe;
>my $pid = open ($pid, "$cmd|") or die;

Surely you want

my $pid = open ($pipe, "$cmd|") or die;

>local $SIG{ALRM} = sub {
>    kill KILL => $pid;
>    }
>alarm ($tmot);
>while (<$pipe>) {print}
>alarm (0);
>
>But under 5.8.4, it doesn't. What appears to happen is that the <$pipe>
>prevents the signal from being delivered. I thought the "kill" wasn't
>working for a while, but when I substituted the corresponding "stop/id" it
>kept reporting "no such process"
>
>Other vitals:
>VMS: 7.1-1H2
>C: DEC C V5.6-003

Configured to use perlio or stdio?  Try

$ define PERL_SIGNALS "unsafe"

and see if that makes any difference.  I have a feeling that what
you're running into is that Perl signals since 5.7.3 are deferred in
order to avoid interrupting things that shouldn't be interrupted.  You
can read up on the whole safe signals thing here:

<http://www.perldoc.com/perl5.8.4/pod/perlipc.html#Deferred-Signals-(Safe-Signals)>



-- 
________________________________________
Craig A. Berry
mailto:[EMAIL PROTECTED]

"... getting out of a sonnet is much more
 difficult than getting in."
                 Brad Leithauser

Reply via email to