#!/usr/bin/perl use strict; use warnings; sub helper { # forked process, wastes 10 seconds for (1..10) { print "helper: start of second $_\n"; select(undef,undef,undef,1); # poor man's sleep, without messing with alarm print "helper: end of second $_\n"; } } sub main { # main process print "Helper will die in 5 seconds\n"; alarm(5); # kill me in five seconds ... exec($^X,$0,"dummy argument") # start perl with this script and a parameter or die "Could not start helper: $!"; } if (@ARGV) { helper(); } else { main(); }