!/usr/bin/perl use strict; use warnings; use IO::CaptureOutput qw(capture capture_exec); use Proc::Killall; use POSIX qw(:signal_h :errno_h :sys_wait_h); &runCommand(); my $pid; unless ( $pid = fork ) { &runCommand(); exit; } $SIG{'CHLD'} = \&Reaper; unless ( $pid = fork ) { &runCommand(); exit; } sub runCommand { my ($stdout, $stderr, $success, $exit_code) = capture_exec('perl', '-e', 'print "Test"'); print "stdout: $stdout\n"; print "stderr: $stderr\n"; print "Success: $success\n"; print "exit code: $exit_code\n"; } sub Reaper { my $pid; waitpid(-1, &WNOHANG); } killall('HUP', -$$);