#!/s/t/tye/bin/perl -w use strict; subroutine( @ARGV ); exit( 0 ); sub subroutine { local( $| )= 1; foreach (1..4) { my $pid= fork; die "Can't fork: $!\n" unless defined $pid; if( ! $pid ) { sleep( $_[$_-1] ); exit(0); } else { print "Started child $pid...\n"; } } foreach (1..4) { my $pid= wait(); print "$_ child ($pid) finished; status is: $?\n"; } } # Usage: fork4 6 4 8 2