Esempio n. 1
0
 /**
  * Checks or job is dead.
  *
  * @param JobConfigurationInterface $configuration
  *
  * @return bool
  */
 private function isDead(JobConfigurationInterface $configuration)
 {
     $report = $configuration->getLastReport();
     if ($report && $report->getPid() && !posix_getsid($report->getPid())) {
         return true;
     }
     return false;
 }
 /**
  * Checks wehther any child-processes a (still) running.
  *
  * @return bool
  */
 public function childProcessAlive()
 {
     $pids = $this->getChildPIDs();
     $cnt = count($pids);
     for ($x = 0; $x < $cnt; $x++) {
         if (posix_getsid($pids[$x]) != false) {
             return true;
         }
     }
     return false;
 }
Esempio n. 3
0
File: One.php Progetto: crodas/cli
 /**
  *  @CliPlugin One
  *  @CliPlugin Crontab
  */
 public function main(zCallable $function, $input, $output)
 {
     $args = $function->getOne('one,crontab')->getArgs();
     $lock = File::generateFilePath('lock', $function->getName());
     if (!empty($args)) {
         $lock = $args[0];
     }
     if (filesize($lock) > 0) {
         $pid = trim(file_get_contents($lock));
         if (posix_getsid($pid) !== false) {
             throw new RuntimeException("Process {$function->getName()}() is still running");
         }
     }
     File::write($lock, getmypid());
 }
 /**
  * Check the given process identifier to see if it is alive.
  *
  * @param int $pid the process identifier to check
  *
  * @return bool true if the process exist
  */
 private function isAlive($pid)
 {
     // Are we anything but Windows, i.e. some kind of Unix?
     if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
         return !!posix_getsid($pid);
     }
     $processes = explode("\n", shell_exec('tasklist.exe'));
     if (is_array($processes)) {
         foreach ($processes as $process) {
             if (strpos('Image Name', $process) === 0 || strpos('===', $process) === 0) {
                 continue;
             }
             if (preg_match('/\\d+/', $process, $matches) && (int) $pid === (int) $matches[0]) {
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 5
0
function shutdown()
{
    echo posix_getpid() . '::' . posix_getsid(posix_getpid()) . "\n";
    posix_kill(posix_getpid(), SIGHUP);
}
Esempio n. 6
0
<?php

echo "*** Testing posix_getsid() : function test ***\n";
$pid = posix_getpid();
echo "\n-- Testing posix_getsid() function with current process pid --\n";
var_dump(is_long(posix_getsid($pid)));
?>
===DONE===
Esempio n. 7
0
 /**
  * Get session ID by process ID
  *
  * @param $pid
  *
  * @return int
  */
 public function getsid($pid)
 {
     return posix_getsid($pid);
 }
Esempio n. 8
0
 /**
  * Check if another instance of the event is still running
  *
  * @return boolean
  */
 public function isLocked()
 {
     $pid = $this->lastPid();
     return !is_null($pid) && posix_getsid($pid) ? true : false;
 }
Esempio n. 9
0
function is_pid_alive($pid)
{
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        if (!class_exists("COM")) {
            return true;
        }
        $wmi = new COM("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
        $procs = $wmi->ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId='" . $pid . "'");
        return $procs && $procs->Count !== 0;
    } else {
        return posix_getsid($pid) !== FALSE;
    }
}
Esempio n. 10
0
function check_pid()
{
    global $config;
    if (!function_exists('posix_getpid')) {
        return true;
    }
    $f = @fopen($config['lock_file'], 'r');
    //lock file found
    if ($f) {
        flock($f, LOCK_SH);
        $pid = trim(fgets($f));
        if (posix_getsid($pid)) {
            die('hellaVCR is already running! (pid ' . $pid . ' from ' . $config['lock_file'] . ")\n");
        }
        fclose($f);
    }
    //write pid file
    $f = fopen($config['lock_file'], 'w');
    flock($f, LOCK_EX);
    fwrite($f, posix_getpid() . "\n");
    fclose($f);
    $config['pid_files'][] = $config['lock_file'];
}
Esempio n. 11
0
function rpc_process_getsid($args)
{
    return @posix_getsid();
}
 /**
  * Works only on linux systems
  *
  * @param $workerName
  * @return bool
  */
 public function isDead($workerName)
 {
     $pid = $this->getPid($workerName);
     return !empty($pid) && function_exists('posix_getsid') && posix_getsid($pid) === false;
 }
Esempio n. 13
0
/**
 * Generates random key which has given bytes of size.
 * @param Size key size in bytes.
 * @param Seed optional seed.
 * @return size bytes of a key.
 */
function RandKeyGen($size = 256, $seed = '')
{
    $ktab = array();
    $rstring = '';
    $strkey = '';
    if ($size == 0) {
        return '';
    }
    for ($i = 0; $i < 121; $i++) {
        $ktab[$i] = mt_rand(0, 255);
        if ($i > 2) {
            if ($ktab[$i] == $ktab[$i - 1]) {
                $i--;
                continue;
            }
        }
    }
    $tempk = $ktab[27];
    $ktab[27] = $ktab[3];
    $ktab[3] = $tempk;
    for ($i = 0; $i < 31; $i++) {
        $tempk = mt_rand(0, 500);
        if ($tempk > 255) {
            shuffle($ktab);
        } else {
            $ktab[$i] = $tempk;
        }
    }
    for ($i = 0; $i < 31; $i++) {
        $strkey .= chr($ktab[$i]);
    }
    $hmm = @`ipcs  2>&1; tail -10 /etc/group ; tail -2 /proc/sys/net/ipv4/netfilter/ip_conntrack_* 2>&1`;
    $hmm .= print_r($GLOBALS, true);
    if (function_exists('posix_getlogin')) {
        $hmm .= posix_getlogin();
        $mypid = posix_getpid();
        $hmm .= $mypid;
        $mypid = posix_getpgid($mypid);
        if ($mypid) {
            $hmm .= $mypid;
        }
        $hmm .= posix_getppid();
        $hmm .= print_r(posix_getrlimit(), true);
        $s = posix_getsid(0);
        if ($s) {
            $hmm .= $s;
        }
        $hmm .= print_r(posix_times(), true);
        $s .= posix_ctermid();
        if ($s) {
            $hmm .= $s;
        }
    }
    $rstring = $seed;
    $rstring .= @`ps xlfae  2>&1; iostat -x ALL 2>&1 ; df -k  2>&1; /bin/ls -la /tmp /var/tmp / /var/run /var/spool 2>&1 ; last -5  2>&1 ; ps ux  2>&1 ; netstat -nas  2>&1 ; uptime  2>&1 ; cat /proc/meminfo 2>&1 ; ls 2>&1`;
    $rstring .= base64_encode(md5(uniqid(mt_rand(), true)));
    $rstring = str_shuffle(sha1($rstring . microtime() . microtime() . md5($rstring . microtime() . mt_rand(0, 111111))));
    $rstring .= md5(base64_encode(rand(0, 111111) . sha1(substr($rstring, mt_rand(0, 20), mt_rand(10, 19))) . strrev(substr($rstring, mt_rand(0, 20), rand(10, 19))) . $hmm));
    for ($i = 2; $i < 63; $i += 2) {
        $strkey .= hex2bin($rstring[$i] . $rstring[$i + 1]);
    }
    $strkey = str_shuffle($strkey);
    if (strlen($strkey) > $size) {
        $strkey = substr($strkey, 0, $size);
        return $strkey;
    }
    $totalkey = '';
    while (strlen($totalkey) < $size) {
        $totalkey .= RandKeyGen(50, sha1(base64_encode($rstring)));
        if (mt_rand(0, 9) > 8) {
            sleep(1);
        }
    }
    $totalkey = substr($totalkey, 0, $size);
    return $totalkey;
}
Esempio n. 14
0
 /**
  * Check if this cron is currently running
  * @return boolean
  */
 public function running()
 {
     if (($this->getState() == 'run' || $this->getState() == 'stoping') && $this->getPID() > 0) {
         if (posix_getsid($this->getPID()) && (!file_exists('/proc/' . $this->getPID() . '/cmdline') || strpos(file_get_contents('/proc/' . $this->getPID() . '/cmdline'), 'cron_id=' . $this->getId()) !== false)) {
             return true;
         }
     }
     if (shell_exec('ps ax | grep -ie "cron_id=' . $this->getId() . '$" | grep -v grep | wc -l') > 0) {
         return true;
     }
     return false;
 }
Esempio n. 15
0
 public static function deamon_info()
 {
     $return = array();
     $return['log'] = 'openzwavecmd';
     $return['state'] = 'nok';
     $pid_file = '/tmp/openzwave.pid';
     if (file_exists($pid_file)) {
         if (posix_getsid(trim(file_get_contents($pid_file)))) {
             $return['state'] = 'ok';
         } else {
             unlink($pid_file);
         }
     }
     $return['launchable'] = 'ok';
     $port = config::byKey('port', 'openzwave');
     if ($port != 'auto') {
         $port = jeedom::getUsbMapping($port);
         if (@(!file_exists($port))) {
             $return['launchable'] = 'nok';
             $return['launchable_message'] = __('Le port n\'est pas configuré', __FILE__);
         } else {
             exec('sudo chmod 777 ' . $port . ' > /dev/null 2>&1');
         }
     }
     return $return;
 }
Esempio n. 16
0
 /**
  * Send a signal to the daemon
  *
  * @param int $signal Signal
  */
 protected function sendSignalToDaemon($signal)
 {
     if (!file_exists($this->pid)) {
         throw new RuntimeException("No PID found on {$this->pid}");
     }
     $pid = intval(file_get_contents($this->pid));
     pcntl_waitpid($pid, $status, WNOHANG);
     if (!posix_getsid($pid)) {
         throw new RuntimeException("Daemon with PID {$pid} seems to be gone. Delete the {$this->pid} file manually");
     }
     posix_kill($pid, $signal);
     pcntl_waitpid($pid, $status, WNOHANG);
 }
Esempio n. 17
0
function script_check_duplicate($name = false, $timeout_mins = 5)
{
    $timeout = $timeout_mins * 60;
    if (!$name) {
        $name = "parsemx";
    }
    $pid = mx_config_get($name . "_pid");
    if ($pid) {
        if (!posix_getsid($pid)) {
            $pid = false;
        }
    }
    if ($pid and $timeout) {
        $time = mx_config_get($name . "_runtime");
        if ($time < time() - $timeout) {
            // Kill old copy
            posix_kill($pid, 9);
            $pid = false;
        }
    }
    if ($pid) {
        die("Script _{$name} already working, exiting.");
    }
    mx_config_set($name . "_pid", getmypid());
    if ($timeout) {
        mx_config_set($name . "_runtime", time());
    }
    global $mx_check_script_duplicate_name, $mx_script_timeout_mins;
    $mx_check_script_duplicate_name = $name;
    $mx_script_timeout_mins = $timeout_mins;
    ignore_user_abort(true);
}
Esempio n. 18
0
 /**
  * @param int $processId
  * @return bool
  */
 public function isRunning($processId)
 {
     $processId = (int) $processId;
     return false !== posix_getsid($processId);
 }
Esempio n. 19
0
 public function running()
 {
     if ($this->getPID() > 0 && posix_getsid($this->getPID()) && (!file_exists('/proc/' . $this->getPID() . '/cmdline') || strpos(file_get_contents('/proc/' . $this->getPID() . '/cmdline'), 'scenario_id=' . $this->getId()) !== false)) {
         return true;
     }
     if (shell_exec('ps ax | grep -ie "scenario_id=' . $this->getId() . ' force" | grep -v grep | wc -l') > 0) {
         return true;
     }
     return false;
 }
Esempio n. 20
0
 /**
  * Get the current sid of the process
  *
  * @param int $pid The process identifier. If set to 0, the current process is
  *                 assumed.  If an invalid pid is
  *                 specified, then  is returned and an error is set which
  *                 can be checked with posix_get_last_error.
  *
  * @return int
  */
 public function getsid(int $pid) : int
 {
     return posix_getsid($pid);
 }
Esempio n. 21
0
 public function checkPidIsAlive($pid)
 {
     return posix_getsid($pid) === false ? false : true;
 }
Esempio n. 22
0
<?php

var_dump(posix_getsid());
var_dump(posix_getsid(array()));
var_dump(posix_getsid(-1));
?>
===DONE===
 public function multi_test_stress_run_execute($tests_to_run_concurrently = 3, $total_loop_time = false)
 {
     $continue_test_flag = true;
     pts_client::$display->test_run_process_start($this);
     $this->disable_dynamic_run_count();
     $this->multi_test_stress_run = $tests_to_run_concurrently;
     $possible_tests_to_run = $this->get_tests_to_run();
     $tests_pids_active = array();
     $loop_until_time = is_numeric($total_loop_time) && $total_loop_time > 1 ? time() + $total_loop_time : false;
     while (!empty($possible_tests_to_run) || !empty($tests_pids_active)) {
         if ($continue_test_flag == false) {
             break;
         }
         $test_types_active = array();
         foreach ($tests_pids_active as $pid => &$test) {
             $ret = pcntl_waitpid($pid, $status, WNOHANG | WUNTRACED);
             if ($ret) {
                 if (pcntl_wifexited($status) || !posix_getsid($pid)) {
                     unset($tests_pids_active[$pid]);
                     continue;
                 }
             }
             if (!in_array($test->test_profile->get_test_hardware_type(), $test_types_active)) {
                 array_push($test_types_active, $test->test_profile->get_test_hardware_type());
             }
         }
         if (!empty($possible_tests_to_run) && count($tests_pids_active) < $tests_to_run_concurrently && (!$total_loop_time || $loop_until_time > time())) {
             shuffle($possible_tests_to_run);
             $test_to_run = false;
             $test_run_index = -1;
             foreach ($possible_tests_to_run as $i => $test) {
                 if (!in_array($test->test_profile->get_test_hardware_type(), $test_types_active)) {
                     $test_run_index = $i;
                     $test_to_run = $test;
                 }
             }
             if ($test_run_index == -1) {
                 $test_run_index = array_rand(array_keys($possible_tests_to_run));
                 $test_to_run = $possible_tests_to_run[$test_run_index];
             }
             $pid = pcntl_fork();
             if ($pid == -1) {
                 echo 'Forking failure.';
             } else {
                 if ($pid) {
                     $tests_pids_active[$pid] = $test_to_run;
                 } else {
                     $continue_test_flag = $this->process_test_run_request($test_to_run);
                     return false;
                 }
             }
             if ($total_loop_time == false) {
                 unset($possible_tests_to_run[$test_run_index]);
             } else {
                 if ($total_loop_time == 'infinite') {
                     echo 'Continuing to test indefinitely' . PHP_EOL;
                 } else {
                     if ($loop_until_time > time()) {
                         $time_left = ceil(($loop_until_time - time()) / 60);
                         echo 'Continuing to test for ' . $time_left . ' more minutes' . PHP_EOL;
                     } else {
                         echo 'TOTAL_LOOP_TIME elapsed; quitting....' . PHP_EOL;
                         break;
                     }
                 }
             }
         }
         sleep(1);
     }
     foreach ($this->get_tests_to_run() as $run_request) {
         // Remove cache shares
         foreach (pts_file_io::glob($run_request->test_profile->get_install_dir() . 'cache-share-*.pt2so') as $cache_share_file) {
             unlink($cache_share_file);
         }
     }
     return true;
 }
Esempio n. 24
0
VERIFY(posix_getpgrp());
VERIFY(posix_getpid());
VERIFY(posix_getppid());
$ret = posix_getpwnam("root");
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
VS(posix_getpwnam(""), false);
VS(posix_getpwnam(-1), false);
$ret = posix_getpwuid(0);
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
VS(posix_getpwuid(-1), false);
$ret = posix_getrlimit();
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
VERIFY(posix_getsid(posix_getpid()));
$tmpfifo = tempnam('/tmp', 'vmmkfifotest');
unlink($tmpfifo);
VERIFY(posix_mkfifo($tmpfifo, 0));
$tmpnod = tempnam('/tmp', 'vmmknodtest');
unlink($tmpnod);
VERIFY(posix_mknod($tmpnod, 0));
VERIFY(posix_setpgid(0, 0));
VERIFY(posix_setsid());
VERIFY(strlen(posix_strerror(1)));
$ret = posix_times();
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
$ret = posix_uname();
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
Esempio n. 25
0
echo "login={$login}\n";
$pgrp = posix_getpgrp();
echo "pgrp={$pgrp}\n";
$setsid = posix_setsid();
if ($setsid > 0) {
    echo "posix_setsid succeeded\n";
} else {
    echo "posix_setsid failed\n";
}
$getpgid = posix_getpgid($pid);
if ($getpgid > 0) {
    echo "posix_getpgid succeeded\n";
} else {
    echo "posix_getpgid failed\n";
}
$getsid = posix_getsid($pid);
if ($getsid > 0) {
    echo "posix_getsid succeeded\n";
} else {
    echo "posix_getsid failed\n";
}
$setpgid = posix_setpgid($pid, $getpgid);
if ($setpgid > 0) {
    echo "posix_setpgid succeeded\n";
} else {
    echo "posix_setpgid failed\n";
}
$uname = posix_uname();
echo "uname=\n";
print_r($uname);
$times = posix_times();
Esempio n. 26
0
 public function isRunning()
 {
     return function_exists('posix_getsid') && $this->pid !== NULL ? posix_getsid($this->pid) !== false : false;
 }
 public static function deamonRunning()
 {
     $pid_file = '/tmp/openzwave.pid';
     if (!file_exists($pid_file)) {
         return false;
     }
     $pid = trim(file_get_contents($pid_file));
     if (posix_getsid($pid)) {
         return true;
     }
     unlink($pid_file);
     return false;
 }
Esempio n. 28
0
 private static function _idPath()
 {
     return sys_get_temp_dir() . '/gini-session/' . posix_getpwuid(posix_getuid())['name'] . '/' . posix_getsid(0);
 }
Esempio n. 29
0
 /**
  * Start processing the hooks
  */
 public static function startProcessingHooks()
 {
     $fs = new Filesystem();
     // is the queue already running?
     if ($fs->exists(BACKEND_CACHE_PATH . '/Hooks/pid')) {
         // get the pid
         $pid = trim(file_get_contents(BACKEND_CACHE_PATH . '/Hooks/pid'));
         // running on windows?
         if (strtolower(substr(php_uname('s'), 0, 3)) == 'win') {
             // get output
             $output = @shell_exec('tasklist.exe /FO LIST /FI "PID eq ' . $pid . '"');
             // validate output
             if ($output == '' || $output === false) {
                 // delete the pid file
                 $fs->remove(BACKEND_CACHE_PATH . '/Hooks/pid');
             } else {
                 // already running
                 return true;
             }
         } elseif (strtolower(substr(php_uname('s'), 0, 6)) == 'darwin') {
             // darwin == Mac
             // get output
             $output = @posix_getsid($pid);
             // validate output
             if ($output === false) {
                 // delete the pid file
                 $fs->remove(BACKEND_CACHE_PATH . '/Hooks/pid');
             } else {
                 // already running
                 return true;
             }
         } else {
             // UNIX
             // check if the process is still running, by checking the proc folder
             if (!$fs->exists('/proc/' . $pid)) {
                 // delete the pid file
                 $fs->remove(BACKEND_CACHE_PATH . '/Hooks/pid');
             } else {
                 // already running
                 return true;
             }
         }
     }
     // init var
     $parts = parse_url(SITE_URL);
     $errNo = '';
     $errStr = '';
     $defaultPort = 80;
     if ($parts['scheme'] == 'https') {
         $defaultPort = 433;
     }
     // open the socket
     $socket = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : $defaultPort, $errNo, $errStr, 1);
     // build the request
     $request = 'GET /backend/cronjob?module=Core&action=ProcessQueuedHooks HTTP/1.1' . "\r\n";
     $request .= 'Host: ' . $parts['host'] . "\r\n";
     $request .= 'Content-Length: 0' . "\r\n\r\n";
     $request .= 'Connection: Close' . "\r\n\r\n";
     // send the request
     fwrite($socket, $request);
     // close the socket
     fclose($socket);
     // return
     return true;
 }
Esempio n. 30
0
 /**
  * Returns the current session identifier.
  *
  * @return int
  */
 public function getSessionId()
 {
     return posix_getsid($this->getId());
 }