function dmn_getpids($nodes, $isstatus = false)
{
    if ($isstatus) {
        if (file_exists(DMN_CTLSTATUSAUTO_SEMAPHORE) && posix_getpgid(intval(file_get_contents(DMN_CTLSTATUSAUTO_SEMAPHORE))) !== false) {
            xecho("Already running (PID " . sprintf('%d', file_get_contents(DMN_CTLSTATUSAUTO_SEMAPHORE)) . ")\n");
            die(10);
        }
        file_put_contents(DMN_CTLSTATUSAUTO_SEMAPHORE, sprintf('%s', getmypid()));
    }
    $dmnpid = array();
    foreach ($nodes as $uname => $node) {
        if (is_dir(DMN_PID_PATH . $uname)) {
            $conf = new DashConfig($uname);
            if ($conf->isConfigLoaded()) {
                if ($node['NodeTestNet'] != $conf->getconfig('testnet')) {
                    xecho("{$uname}: Configuration inconsistency (testnet/" . $node['NodeTestNet'] . "/" . $conf->getconfig('testnet') . ")\n");
                }
                if ($node['NodeEnabled'] != $conf->getmnctlconfig('enable')) {
                    xecho("{$uname}: Configuration inconsistency (enable/" . $node['NodeEnabled'] . "/" . $conf->getmnctlconfig('enable') . ")\n");
                }
                $pid = dmn_getpid($uname, $conf->getconfig('testnet') == '1');
                $dmnpiditem = array('pid' => $pid, 'uname' => $uname, 'conf' => $conf, 'type' => $node['NodeType'], 'enabled' => $node['NodeEnabled'] == 1, 'testnet' => $node['NodeTestNet'] == 1, 'dashd' => $node['VersionPath'], 'currentbin' => '', 'keeprunning' => $node['KeepRunning'] == 1, 'keepuptodate' => $node['KeepUpToDate'] == 1, 'versionraw' => $node['VersionRaw'], 'versiondisplay' => $node['VersionDisplay'], 'versionhandling' => $node['VersionHandling']);
                if ($pid !== false) {
                    if (file_exists('/proc/' . $pid . '/exe')) {
                        $currentbin = readlink('/proc/' . $pid . '/exe');
                        $dmnpiditem['currentbin'] = $currentbin;
                        if ($currentbin != $node['VersionPath']) {
                            xecho("{$uname}: Binary mismatch ({$currentbin} != " . $node['VersionPath'] . ")");
                            /*              if ($dmnpiditem['keepuptodate']) {
                                            echo " [Restarting to fix]\n";
                                            dmn_startstop(array($dmnpiditem),"restart",($node['NodeTestNet'] == 1),$node['NodeType']);
                                            sleep(3);
                                            $pid = dmn_getpid($uname,($conf->getconfig('testnet') == '1'));
                                            $dmnpiditem['pid'] = $pid;
                                            if (($pid !== false) && (file_exists('/proc/'.$pid.'/exe'))) {
                                              $currentbin = readlink('/proc/'.$pid.'/exe');
                                              $dmnpiditem['currentbin'] = $currentbin;
                                              if ($currentbin != $node['VersionPath']) {
                                                xecho("$uname: Binary mismatch ($currentbin != ".$node['VersionPath'].") [Restart failed, need admin]\n");
                                              }
                                            }
                                          }
                                          else {  */
                            echo " [Restart to fix]\n";
                            //              }
                        }
                    } else {
                        xecho("{$uname}: process ID {$pid} has no binary information (crashed?)\n");
                    }
                } else {
                    xecho("{$uname}: process ID not found\n");
                }
                $dmnpid[] = $dmnpiditem;
            }
        }
    }
    usort($dmnpid, "dmnpidcmp");
    return $dmnpid;
}
    $nodepath = $nodepath1;
} elseif (is_dir($nodepath2)) {
    $nodepath = $nodepath2;
} elseif (is_dir($nodepath3)) {
    $nodepath = $nodepath3;
} else {
    xecho("Directory {$nodepath3} not found.\n");
    die(1);
}
if (file_exists($outputfile)) {
    xecho("Output file already exists. Aborting.\n");
    die(5);
}
xecho("Loading configuration for {$uname}: ");
$conf = new DashConfig($uname);
if ($conf->isConfigLoaded()) {
    echo "OK\n";
} else {
    echo "Error (Loading configuration)\n";
    die(2);
}
xecho("Executing RPC command '{$rpccommand}': ");
$rpc = new \elbereth\EasyDash($conf->getconfig('rpcuser'), $conf->getconfig('rpcpassword'), 'localhost', $conf->getconfig('rpcport'));
$rpclist = explode(' ', $rpccommand);
$rpcparams = array();
for ($x = 1; $x < count($rpclist); $x++) {
    if (ctype_digit($rpclist[$x])) {
        $rpcparams[] = intval($rpclist[$x]);
    } elseif (is_numeric($rpclist[$x])) {
        $rpcparams[] = floatval($rpclist[$x]);
    } else {