$exit = &command( "/bin/snore", 60 ); #### eval { local $SIG{ALRM} = sub { die "alarm clock restart" }; alarm 10; flock(FH, 2); # blocking write lock alarm 0; }; if ($@ and $@ !~ /alarm clock restart/) { die } #### #! /usr/bin/perl use strict; my $exit = &command( "sleep 4; exit 99;", 1 ); if(! defined( $exit ) ) { print "error: command timed-out\n" } else { print "yay, it worked, exit: $exit\n" } sub command { my( $command, $timeout ) = @_; my $pid; eval { local $SIG{ALRM} = sub { die }; if( $pid = fork ) { alarm $timeout } else { exec( $command ) || die( "Couldn't exec $command" ) } waitpid( $pid, 0 ); alarm 0; }; if( $@ ) { return undef } else { return $? / 256 } } #### my JAPH: print"Just another Perl hacker\n"; # ^ look, no space! pretty tricky hey?