my ($self) = @_;
my $cmd = 'ps x -o state,pid,command -w -w | grep runWorker.pl | grep -v "grep runWorker.pl" ';
# FIXME: if we want to incorporate Meadow->pipeline_name() filtering here,
# a dummy parameter to the runWorker.pl should probably be introduced
# for 'ps' to be able to externally differentiate between local workers
# working for different hives
# (but at the moment such a feature is unlikely to be be in demand).
my %status_hash = ();
foreach my $line (`$cmd`) {
my ($pre_status, $worker_pid, $job_name) = split(/\s+/, $line);
my $status = {
'R' => 'RUN', # running
'S' => 'RUN', # sleeping (sleeping for less than 20 sec on a Mac)
'I' => 'RUN', # Mac: idle (sleeping for more than 20 sec)
'D' => 'RUN', # Linux: uninterruptible sleep, usually IO
'U' => 'RUN', # Mac: uninterruptible wait
'T' => 'SSUSP' # stopped process
}->{ substr($pre_status,0,1) }; # only take the first character because of Mac's additional modifiers
# Note: you can locally 'kill -19' a worker to suspend it and 'kill -18' a worker to resume it
$status_hash{$worker_pid} = $status;
}
return \%status_hash;
}