# Initialization # Read input file, calls to system('bowtie2', ...) and system('samtools', ...) use strict; use warnings; use Carp qw(confess); use Sys::Info::Device::CPU; use Sys::Info::Constants qw( :device_cpu ); my $info = Sys::Info->new; my $cpu = $info->device( CPU => {} ); my $nthreads = $cpu->count; print "$nthreads threads\n"; while ($nthreads--) { my $pid = fork; confess ("Can't fork: $!") unless defined $pid; if (! $pid) { print "child process: $$\n"; # this line never gets executed by some of the children # Do a bunch of processing using intermediate files as input, using Bio::DB::Sam->get_features_by_location() to access intermediate files exit 0; } } # parent continues here: my $pid = 0; my $ok = 1; while ($pid != -1) { $pid = wait; last if $pid == -1; my $err=$?; if ($err) { print("one of the children died: pid=$pid, err=$err\n"); $ok = 0; } } if (! $ok) { confess "some child processes died."; } print "all done, yay\n";