<?php

require __DIR__ . '/../../share/app.php';
$id = intval($_GET['id']);
$pid = ts_pid($id);
?>
<pre><?php 
e(shell_ps($pid));
?>
</pre>
<pre><?php 
e(shell_pstree($pid));
?>
</pre>
<?php 
/*
<pre>
    <?php var_dump(ps('pid,ppid,pgid,pcpu,cputime,etime,vsize,comm,args')) ?>
</pre>
*/
?>

    }
    header('Location: index.php');
    exit;
}
if (isset($_GET['remove'])) {
    ts_remove(intval($_GET['remove']));
    header('Location: index.php');
    exit;
}
if (isset($_GET['up'])) {
    ts_up(intval($_GET['up']));
    header('Location: index.php');
    exit;
}
if (isset($_GET['kill'])) {
    $pid = ts_pid($_GET['kill']);
    exec(sprintf('kill -KILL %s', escapeshellarg($pid)));
    header('Location: index.php');
    exit;
}
if (isset($_GET['add'])) {
    $d = realpath(__DIR__ . '/../../bin');
    $_SESSION['FLASH'] = ts_enqueue("{$d}/long-running-task");
    header('Location: index.php');
    exit;
}
if (isset($_GET['clear'])) {
    ts_clear();
    header('Location: index.php');
    exit;
}