#!/usr/bin/perl -w $SIG{ALRM}= sub { my($user,$system) = (times)[0,1]; my $totaltime = $user + $system; if ($totaltime > 1.5) { if (fork() != 0) { # No error checking. Bad Monk! wait; exit(0); } } alarm(1); }; $| = 1; alarm(1); # Comment out to not use fork srand(0); for(my $i=0;$i<10_000_000;$i++) { if (($i % 1_000_000) == 0) { printf "%05d (pid %05d)\n", int(rand() * 10_000),$$; } }