in reply to Timing External Program Execution

This is done with the signal handler for the alarm call:
use warnings; use strict; my $fuse = 10; # Seconds foreach (<*.mp3>) { print "$_\n"; # Update on progress # If the fork() produces a process... if (my $pid = fork()) { # ...wait for it to finish. wait(); } else { # This causes the process to exit on # an alarm call. $SIG{ALRM} = sub { exit(); }; # This sets the timer on the alarm alarm($fuse); # This runs a command that takes a long # time and has to be stopped early. system("/bin/sleep 10000"); # Important to exit() here or you'll # keep going through the loop creating # more processes! exit(); } }

Replies are listed 'Best First'.
Re: Re: Timing External Program Execution
by agentv (Friar) on Oct 22, 2002 at 20:04 UTC
    ...very nicely coded example. Thank you. (++)

    ...All the world looks like -well- all the world, when your hammer is Perl.
    ---v