#!/usr/bin/perl -w use strict; open(O,'>', "$$.tmp"); select O; $| = 1; # make output unbuffered print STDOUT "file is $$.tmp\n"; $SIG{'CHLD'} = \&reap; if ( (my $pid = fork()) == 0 ) { sleep 1; print "child ($$) here\n"; close O; exit 0; } else { print "parent ($$) here\n"; sleep 2; print "parent ($$) waking up..\n"; } sub reap { my $pid = wait; print "reaped PID $pid\n"; } __END__ file is 4782.tmp