my $redo; # flag sub status () { $SIG{USR1} = \&status; print STDERR "Currently running: $StartedProcess\n"; $redo = 1; # re-set flag } # Opens external program, and as long as it exists, checks # if there is data in the pipe (STDOUT/STDERR) sub createProcess () { my($line, $selector, @ready, $fh); $StartedProcess = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, "./external.pp"); close(CMD_IN); $selector = IO::Select->new(); $selector->add(*CMD_ERR, *CMD_OUT); $redo = 1; # set flag while($redo) { $redo = 0; # clear flag while(@ready = $selector->can_read) { # do some operations on STDOUT/STDERR here } warn "after inner loop\n"; } warn "closing CMD_OUT and CMD_ERR\n"; close(CMD_OUT); close(CMD_ERR); }