# this is a direct c&p from a larger opus of code # but you should get the idea. # command is worked out earlier depending on the # platform we are running on my $timeout=60; my @sqlo; my $Q = new Thread::Queue; threads->create( \&RunInThread, $command, $Q ); my $pid = $Q->dequeue; for (1..$timeout) { sleep 1; my $result=$Q->dequeue_nb; # non_block, return undef if nowt on queue next unless $result; # twas nowt on queue if ($result eq "$pid is done") { $trace->trace("SQL process finished within $_ seconds"); last; } push @sqlo, $result; } my $killed = kill 9, $pid if kill 0, $pid; # kill child if still alive if ($killed) { $trace->trace("Had to kill SQL process, taking more than $timeout secs"); } sub RunInThread { my ( $cmd, $Q) = @_; my $pid = open CMD, "$cmd |" or $trace->die("$cmd : $!"); $Q->enqueue($pid); $Q->enqueue( $_ ) while defined( $_ = ); $Q->enqueue("$pid is done"); }