[sf-perl] not understanding program behavior with alarm()
Francisco Obispo
fobispo at isc.org
Fri Feb 3 14:57:23 PST 2012
Perl's system() call performs a fork() on the specified process,
you might want to try exec() instead..
On Feb 3, 2012, at 2:43 PM, David Alban wrote:
> greetings,
>
> my code is not doing what i expect. i have:
>
> $ cat junk.test.alarm
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> eval {
> local $SIG{ ALRM } = sub { die "alarm\n"; };
> alarm 5;
> system 'bash', "$ENV{ HOME }/junk.sh";
> alarm 0;
> };
>
> if ( $@ ) {
> if ( $@ eq "alarm\n" ) {
> die "timed out!\n";
> }
> else {
> die "non-timeout error: $!\n";
> }
> }
>
> print "right before exit stmt\n";
>
> exit 0;
>
> and:
>
> $ cat ~/junk.sh
> #!/bin/bash
>
> export PATH=/sbin:/bin:/usr/sbin:/usr/bin
>
> i=0
> while true ; do
> i=$(( $i + 1 ))
> echo $i
> sleep 1
> done
>
> exit 0
>
> when i run, i get:
>
> $ perl junk.test.alarm
> $ perl junk.test.alarm
> 1
> 2
> 3
> 4
> 5
> timed out!
>
> dalban at srwd00reg008 Fri Feb 03 22:41:37
> ~
> $ 6
> 7
> 8
> 9
> 10
> 11
> 12
> 13
>
> with junk.sh continuing until i kill it from the command line.
>
> what am i missing?
>
> should the die() stop junk.sh?
>
> thanks,
> david
> --
> Live in a world of your own, but always welcome visitors.
> ***
> Rule of law is for the little people.
> http://www.amazon.com/Liberty-Justice-Some-Equality-Powerful/dp/0805092056
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
More information about the SanFrancisco-pm
mailing list