<?php if (support("kill") && $_POST && !$error) { $killed = 0; foreach ((array) $_POST["kill"] as $val) { if (kill_process($val)) { $killed++; } } queries_redirect(ME . "processlist=", lang('%d process(es) have been killed.', $killed), $killed || !$_POST["kill"]); } page_header(lang('Process list'), $error); ?> <form action="" method="post"> <table cellspacing="0" onclick="tableClick(event);" ondblclick="tableClick(event, true);" class="nowrap checkable"> <?php // HTML valid because there is always at least one process $i = -1; foreach (process_list() as $i => $row) { if (!$i) { echo "<thead><tr lang='en'>" . (support("kill") ? "<th> " : ""); foreach ($row as $key => $val) { echo "<th>{$key}" . doc_link(array('sql' => "show-processlist.html#processlist_" . strtolower($key), 'pgsql' => "monitoring-stats.html#PG-STAT-ACTIVITY-VIEW", 'oracle' => "../b14237/dynviews_2088.htm")); } echo "</thead>\n"; } echo "<tr" . odd() . ">" . (support("kill") ? "<td>" . checkbox("kill[]", $row[$jush == "sql" ? "Id" : "pid"], 0) : ""); foreach ($row as $key => $val) { echo "<td>" . ($jush == "sql" && $key == "Info" && preg_match("~Query|Killed~", $row["Command"]) && $val != "" || $jush == "pgsql" && $key == "current_query" && $val != "<IDLE>" || $jush == "oracle" && $key == "sql_text" && $val != "" ? "<code class='jush-{$jush}'>" . shorten_utf8($val, 100, "</code>") . ' <a href="' . h(ME . ($row["db"] != "" ? "db=" . urlencode($row["db"]) . "&" : "") . "sql=" . urlencode($val)) . '">' . lang('Clone') . '</a>' : nbsp($val)); }
echo RSYNC_PID() . "\n"; die; } if ($argv[1] == "--start") { $GLOBALS["OUTPUT"] = true; start(); die; } if ($argv[1] == "--stop") { $GLOBALS["OUTPUT"] = true; stop(); die; } if ($argv[1] == "--kill") { $GLOBALS["OUTPUT"] = true; kill_process(); die; } if ($argv[1] == "--logs") { $GLOBALS["OUTPUT"] = true; ChecksLogs(); die; } if ($argv[1] == "--schedule") { $GLOBALS["OUTPUT"] = true; rsync_mirror_execute(true); ChecksLogs(); die; } if ($argv[1] == "--start-exec-manu") { $GLOBALS["NOTIMECHECK"] = true;
$macros_pids = get_pids('fabui/python/gmacro.py'); $create_pids = get_pids('fabui/python/gpusher_fast.py'); kill_process(array_merge($macros_pids, $create_pids)); $selftest_pids = get_pids('python/self_test.py'); $bed_cal_pids = get_pids('python/manual_bed_lev.py'); $rscan_pids = get_pids('/fabui/python/r_scan.py'); $sscan_pids = get_pids('/fabui/python/s_scan.py'); $pscan_pids = get_pids('/fabui/python/p_scan.py'); $triangulation_pids = get_pids('/fabui/python/triangulation.py'); $join_pids = get_pids('/fabui/python/join.py'); $slic3rwrapper_pids = get_pids('/fabui/python/slic3r_wrapper.py'); $meshlabwrapper_pids = get_pids('/fabui/python/meshlab_wrapper.py'); $meshlabserver_pids = get_pids('meshlabserver'); $xvfb_pids = get_pids('xvfb-run'); $slic3r_pids = get_pids('/fabui/slic3r/slic3r'); $all_pids = array_merge($selftest_pids, $bed_cal_pids, $rscan_pids, $sscan_pids, $pscan_pids, $triangulation_pids, $join_pids); $all_pids = array_merge($all_pids, $slic3rwrapper_pids, $meshlabwrapper_pids, $meshlabserver_pids, $xvfb_pids, $slic3r_pids); //kill all pids kill_process($all_pids); $end = time(); //clean up memory //shell_exec('sudo chmod 0666 /proc/sys/vm/drop_caches'); shell_exec('sudo sh -c "echo 1 >/proc/sys/vm/drop_caches"'); shell_exec('sudo sh -c "echo 2 >/proc/sys/vm/drop_caches"'); shell_exec('sudo sh -c "echo 3 >/proc/sys/vm/drop_caches"'); //shell_exec('sudo chmod 0644 /proc/sys/vm/drop_caches'); $_command = 'sudo python ' . PYTHON_PATH . 'force_reset.py'; shell_exec($_command); sleep(1); include '/var/www/fabui/script/boot.php'; echo json_encode($all_pids);
/** * STOP ALL */ public function stop_all() { $this->load->helper('os_helper'); $macros_pids = get_pids('fabui/python/gmacro.py'); $create_pids = get_pids('fabui/python/gpusher_fast.py'); $selftest_pids = get_pids('python/self_test.py'); $bed_cal_pids = get_pids('python/manual_bed_lev.py'); $all_pids = array_merge($macros_pids, $create_pids, $selftest_pids, $bed_cal_pids); kill_process($all_pids); $_command = 'sudo python ' . PYTHONPATH . 'force_reset.py'; shell_exec($_command); sleep(3); echo 1; }
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2 * */ if (php_sapi_name() !== "cli") { die; } /** * Configuration file */ include realpath(dirname(__FILE__) . "/../config.inc.php"); /** * Database file */ include realpath(dirname(__FILE__) . "/../db.inc.php"); /** * Process */ include realpath(dirname(__FILE__) . "/../functions/functions.process.php"); //end any other process $p = is_process_running(2); if ($p) { kill_process($p); end_process($p); } start_process(realpath(dirname(__FILE__) . "/../admin/systemsortprocess.php"), 2); $p = is_process_running(); if ($p) { kill_process($p); end_process($p); } start_process(realpath(dirname(__FILE__) . "/../admin/process.php"));
function kill($items, $pid) { global $handles; foreach ($handles as $index => $handle) { if ($handle["pid"] == $pid) { if (kill_process($handle) == True) { unset($handles[$index]); privmsg($items["destination"], $items["nick"], "successfully terminated process with pid {$pid}"); } else { privmsg($items["destination"], $items["nick"], "error terminating process with pid {$pid}"); } return; } } privmsg($items["destination"], $items["nick"], "unable to find process with pid {$pid}"); }
function pleac_Sorting_an_Array_Numerically() { // PHP offers a rich set of sorting functions. Key features: // * Inplace sorts; the original array, not a a copy, is sorted // * Separate functions exist for sorting [both ascending and descending order]: // - By value, assign new keys / indices [sort, rsort] // - By key [ksort, krsort] (for non-numerically indexed arrays) // - By value [asort, arsort] // - As above, but using a user-defined comparator [i.e. callback function] // [usort, uasort, uksort] // - Natural order sort [natsort] // * Significantly, if sorting digit-only elements, whether strings or numbers, // 'natural order' [i.e. 1 before 10 before 100 (ascending)] is retained. If // the elements are alphanumeric e.g. 'z1', 'z10' then 'natsort' should be // used [note: beware of 'natsort' with negative numbers; prefer 'sort' or 'asort'] $unsorted = array(7, 12, -13, 2, 100, 5, 1, -2, 23, 3, 6, 4); sort($unsorted); // -13, -2, 1, 2, 3, 4, 5, 6, 7, 12, 23, 100 rsort($unsorted); // 100, 23, 12, 7, 6, 5, 4, 3, 2, 1, -2, -13 asort($unsorted); // -13, -2, 1, 2, 3, 4, 5, 6, 7, 12, 23, 100 arsort($unsorted); // 100, 23, 12, 7, 6, 5, 4, 3, 2, 1, -2, -13 natsort($unsorted); // -2, -13, 1, 2, 3, 4, 5, 6, 7, 12, 23, 100 // ------------ function ascend($left, $right) { return $left > $right; } function descend($left, $right) { return $left < $right; } // ------------ usort($unsorted, 'ascend'); // -13, -2, 1, 2, 3, 4, 5, 6, 7, 12, 23, 100 usort($unsorted, 'descend'); // 100, 23, 12, 7, 6, 5, 4, 3, 2, 1, -2, -13 uasort($unsorted, 'ascend'); // -13, -2, 1, 2, 3, 4, 5, 6, 7, 12, 23, 100 uasort($unsorted, 'descend'); // 100, 23, 12, 7, 6, 5, 4, 3, 2, 1, -2, -13 // ---------------------------- function kill_process($pid) { // Is 'killable' ? if (!posix_kill($pid, 0)) { return; } // Ok, so kill in two stages posix_kill($pid, 15); // SIGTERM sleep(1); posix_kill($pid, 9); // SIGKILL } function pid($pentry) { $p = preg_split('/\\s/', trim($pentry)); return $p[0]; } $processes = array_map('pid', array_slice(preg_split('/\\n/', `ps ax`), 1, -1)); sort($processes); echo join(' ,', $processes) . "\n"; echo 'Enter a pid to kill: '; if ($pid = trim(fgets(STDIN))) { kill_process($pid); } }