当前位置: 首页>>代码示例>>PHP>>正文


PHP posix_getpgid函数代码示例

本文整理汇总了PHP中posix_getpgid函数的典型用法代码示例。如果您正苦于以下问题:PHP posix_getpgid函数的具体用法?PHP posix_getpgid怎么用?PHP posix_getpgid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了posix_getpgid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onConsoleCommand

 /**
  * @param ConsoleCommandEvent $event
  *
  * @return void
  * @throws CommandAlreadyRunningException
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     // generate pid file name
     $commandName = $event->getCommand()->getName();
     // check for exceptions
     if (in_array($commandName, $this->exceptionsList)) {
         return;
     }
     $clearedCommandName = $this->cleanString($commandName);
     $pidFile = $this->pidFile = $this->pidDirectory . "/{$clearedCommandName}.pid";
     // check if command is already executing
     if (file_exists($pidFile)) {
         $pidOfRunningCommand = file_get_contents($pidFile);
         $elements = explode(":", $pidOfRunningCommand);
         if ($elements[0] == gethostname()) {
             if (posix_getpgid($elements[1]) !== false) {
                 throw (new CommandAlreadyRunningException())->setCommandName($commandName)->setPidNumber($pidOfRunningCommand);
             } else {
                 // pid file exist but the process is not running anymore
                 unlink($pidFile);
             }
         } else {
             throw (new CommandAlreadyRunningException())->setCommandName($commandName)->setPidNumber($pidOfRunningCommand);
         }
     }
     // if is not already executing create pid file
     //file_put_contents($pidFile, getmypid());
     // Añadimos hostname para verificar desde que frontal se estan ejecutando
     $string = gethostname() . ":" . getmypid();
     file_put_contents($pidFile, $string);
     // register shutdown function to remove pid file in case of unexpected exit
     register_shutdown_function(array($this, 'shutDown'), null, $pidFile);
 }
开发者ID:jordigracia,项目名称:command-lock-bundle,代码行数:39,代码来源:CommandLockEventListener.php

示例2: checkPid

 private function checkPid($check)
 {
     if (posix_getpgid($check) !== false) {
         return true;
     }
     return false;
 }
开发者ID:kissit,项目名称:kiss-ops,代码行数:7,代码来源:kisslock.php

示例3: acquire

 /**
  * @param int $wait max time to wait to acquire lock (seconds)
  * @return bool TRUE if acquired; else false
  */
 function acquire($wait)
 {
     $totalDelay = 0;
     // total total spent waiting so far (seconds)
     $nextDelay = 0;
     while ($totalDelay < $wait) {
         if ($nextDelay) {
             sleep($nextDelay);
             $totalDelay += $nextDelay;
         }
         if (!file_exists($this->lockFile)) {
             file_put_contents($this->lockFile, $this->pid);
             return TRUE;
         }
         $lockPid = (int) trim(file_get_contents($this->lockFile));
         if ($lockPid == $this->pid) {
             return TRUE;
         }
         if (!posix_getpgid($lockPid)) {
             file_put_contents($this->lockFile, $this->pid);
             return TRUE;
         }
         $nextDelay = rand($this->minDelay, min($this->maxDelay, $wait - $totalDelay));
     }
     return FALSE;
 }
开发者ID:jaapjansma,项目名称:civicrm-buildkit,代码行数:30,代码来源:pidlockfile.php

示例4: dmn_getpids

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;
}
开发者ID:elbereth,项目名称:dashninja-ctl,代码行数:59,代码来源:dmnctl.script.inc.php

示例5: __construct

 /**
  * Create a ParallelChildCollector that will collect
  * issues as normal, but emit them to a message queue
  * for collection by a
  * \Phan\Output\Collector\ParallelParentCollector.
  */
 public function __construct()
 {
     assert(extension_loaded('sysvsem'), 'PHP must be compiled with --enable-sysvsem in order to use -j(>=2).');
     assert(extension_loaded('sysvmsg'), 'PHP must be compiled with --enable-sysvmsg in order to use -j(>=2).');
     // Create a message queue for this process group
     $message_queue_key = posix_getpgid(posix_getpid());
     $this->message_queue_resource = msg_get_queue($message_queue_key);
 }
开发者ID:nagyistge,项目名称:phan,代码行数:14,代码来源:ParallelChildCollector.php

示例6: testCheckIfPidIsRunning

 public function testCheckIfPidIsRunning()
 {
     // Start up a testing webserver.
     $host = "localhost";
     $port = 8080;
     $script = realpath(__DIR__ . "/routers/router-200.php");
     $server = new ShamServer($host, $port, $script);
     $pid = $server->getPid();
     $this->assertNotFalse(posix_getpgid($pid));
     $server->stop();
 }
开发者ID:pjdietz,项目名称:shamserver,代码行数:11,代码来源:ShamServerTest.php

示例7: is_running

 /**
  * public static function running
  *
  * @access public
  * @return bool $running
  */
 public static function is_running()
 {
     if (!file_exists(Config::$pid_file)) {
         return false;
     }
     $pid = file_get_contents(Config::$pid_file);
     if (posix_getpgid($pid) === false) {
         unlink(Config::$pid_file);
         return false;
     }
     return true;
 }
开发者ID:tigron,项目名称:skeleton-transaction,代码行数:18,代码来源:Daemon.php

示例8: getRelatedConsoleNodeProcess

 protected function getRelatedConsoleNodeProcess()
 {
     $consoleNodeProcess = $this->getConsoleNodeProcessRepository()->findOneBy(['name' => $this->getName(), 'consoleNode' => $this->consoleNode]);
     if ($consoleNodeProcess instanceof ConsoleNodeProcessInterface === false) {
         $this->writeLog(self::MSG_COMMAND_NOT_RUNNING, [$this->getName(), $this->consoleNode->getHostName()]);
         exit;
     }
     if (posix_getpgid($consoleNodeProcess->getPid()) === false) {
         $this->writeLog(self::MSG_COMMAND_MAY_HAVE_CRASHED, [$this->getName(), $this->consoleNode->getHostName()]);
     }
     return $consoleNodeProcess;
 }
开发者ID:madrakio,项目名称:persistent-command-bundle,代码行数:12,代码来源:AbstractContinuousPersistentCommand.php

示例9: __construct

 /**
  * Create a ParallelParentCollector that will collect
  * issues via a message queue. You'll want to do the
  * real collection via
  * \Phan\Output\Collector\ParallelChildCollector.
  *
  * @param IssueCollectorInterface $base_collector
  * A collector must be given to which collected issues
  * will be passed
  */
 public function __construct(IssueCollectorInterface $base_collector)
 {
     assert(extension_loaded('sysvsem'), 'PHP must be compiled with --enable-sysvsem in order to use -j(>=2).');
     assert(extension_loaded('sysvmsg'), 'PHP must be compiled with --enable-sysvmsg in order to use -j(>=2).');
     $this->base_collector = $base_collector;
     // Create a message queue for this process group
     $message_queue_key = posix_getpgid(posix_getpid());
     $this->message_queue_resource = msg_get_queue($message_queue_key);
     // Listen for ALARMS that indicate we should flush
     // the queue
     pcntl_sigprocmask(SIG_UNBLOCK, array(SIGUSR1), $old);
     pcntl_signal(SIGUSR1, function () {
         $this->readQueuedIssues();
     });
 }
开发者ID:nagyistge,项目名称:phan,代码行数:25,代码来源:ParallelParentCollector.php

示例10: stop

 public function stop()
 {
     $pid = @file_get_contents($this->config['pid']);
     if ($pid) {
         posix_kill($pid, SIGTERM);
         for ($i = 0; $i = 10; $i++) {
             sleep(1);
             if (!posix_getpgid($pid)) {
                 unlink($this->config['pid']);
                 return;
             }
         }
         die("don't stopped\r\n");
     } else {
         die("already stopped\r\n");
     }
 }
开发者ID:pzverr,项目名称:websocket,代码行数:17,代码来源:Server.php

示例11: checkRunningCrons

 public function checkRunningCrons()
 {
     $entityManager = $this->managerRegistry->getManagerForClass('DspSoftsCronManagerBundle:CronTaskLog');
     $cronTaskLogRepo = $entityManager->getRepository('DspSoftsCronManagerBundle:CronTaskLog');
     $cronTaskLogs = $cronTaskLogRepo->searchRunning();
     foreach ($cronTaskLogs as $cronTaskLog) {
         if (posix_getpgid($cronTaskLog->getPid()) === false) {
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('PID %s not found for cron task log id %s, terminating task...', $cronTaskLog->getPid(), $cronTaskLog->getId()));
             }
             $cronTaskLog->setStatus(CronTaskLog::STATUS_FAILED);
             $cronTaskLog->setPid(null);
             $cronTaskLog->setDateEnd(new \DateTime());
             $entityManager->persist($cronTaskLog);
             $entityManager->flush();
         }
     }
 }
开发者ID:dspsofts,项目名称:cronmanager-bundle,代码行数:18,代码来源:CronManipulator.php

示例12: alarmHandler

 /**
  * Poll the sigFile looking for a signal to self-deliver.
  * This is useful if we don't know the PID of the worker - we can easily deliver signals
  * if we only know the ClassName and ID of the DataObject.
  */
 public function alarmHandler()
 {
     $sigFile = $this->args['sigFile'];
     if (file_exists($sigFile) && is_readable($sigFile) && is_writable($sigFile)) {
         $signal = (int) file_get_contents($sigFile);
         if (is_int($signal) && in_array((int) $signal, [SIGTERM, SIGINT, SIGQUIT, SIGUSR1, SIGUSR2, SIGCONT])) {
             echo sprintf('[-] Signal "%s" received, delivering to own process group, PID "%s".' . PHP_EOL, $signal, getmypid());
             // Mark the signal as received.
             unlink($sigFile);
             // Dispatch to own process group.
             $pgid = posix_getpgid(getmypid());
             if ($pgid <= 0) {
                 echo sprintf('[-] Unable to send signal to invalid PGID "%s".' . PHP_EOL, $pgid);
             } else {
                 posix_kill(-$pgid, $signal);
             }
         }
     }
     // Wake up again soon.
     pcntl_alarm(1);
 }
开发者ID:silverstripe,项目名称:deploynaut,代码行数:26,代码来源:DeployJob.php

示例13: checkExistingInstance

 private function checkExistingInstance()
 {
     $pidFile = Config::get('ajumamoro:pid_file', './.ajumamoro.pid');
     if (file_exists($pidFile) && is_readable($pidFile)) {
         $oldPid = file_get_contents($pidFile);
         if (posix_getpgid($oldPid) === false) {
             return false;
         } else {
             Logger::error("An already running ajumamoro process with pid {$oldPid} detected.\n");
             return true;
         }
     } else {
         if (file_exists($pidFile)) {
             Logger::error("Could not read pid file [{$pidFile}].");
             return true;
         } else {
             if (is_writable(dirname($pidFile))) {
                 return false;
             } else {
                 return false;
             }
         }
     }
 }
开发者ID:ekowabaka,项目名称:ajumamoro,代码行数:24,代码来源:Start.php

示例14: onConsoleCommand

 /**
  * @param ConsoleCommandEvent $event
  *
  * @return void
  * @throws CommandAlreadyRunningException
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     // generate pid file name
     $commandName = $event->getCommand()->getName();
     // check for exceptions
     if (in_array($commandName, $this->exceptionsList)) {
         return;
     }
     $clearedCommandName = $this->cleanString($commandName);
     $pidFile = $this->pidFile = $this->pidDirectory . "/{$clearedCommandName}.pid";
     // check if command is already executing
     if (file_exists($pidFile)) {
         $pidOfRunningCommand = file_get_contents($pidFile);
         if (posix_getpgid($pidOfRunningCommand) !== false) {
             throw (new CommandAlreadyRunningException())->setCommandName($commandName)->setPidNumber($pidOfRunningCommand);
         }
         // pid file exist but the process is not running anymore
         unlink($pidFile);
     }
     // if is not already executing create pid file
     file_put_contents($pidFile, getmypid());
     // register shutdown function to remove pid file in case of unexpected exit
     register_shutdown_function(array($this, 'shutDown'), null, $pidFile);
 }
开发者ID:ffreitas-br,项目名称:command-lock-bundle,代码行数:30,代码来源:CommandLockEventListener.php

示例15: acquire

 /**
  * @param int $wait max time to wait to acquire lock (seconds)
  * @return bool TRUE if acquired; else false
  */
 public function acquire($wait)
 {
     if (!$this->hasDeps()) {
         return TRUE;
     }
     $waitUs = $wait * 1000 * 1000;
     $totalDelayUs = 0;
     // total total spent waiting so far (microseconds)
     $nextDelayUs = 0;
     while ($totalDelayUs < $waitUs) {
         if ($nextDelayUs) {
             usleep($nextDelayUs);
             $totalDelayUs += $nextDelayUs;
         }
         if (!$this->fs->exists($this->lockFile)) {
             $this->fs->dumpFile($this->lockFile, $this->pid);
             return TRUE;
         }
         $lockPid = (int) trim(file_get_contents($this->lockFile));
         if ($lockPid == $this->pid) {
             return TRUE;
         }
         if (!posix_getpgid($lockPid)) {
             $this->fs->dumpFile($this->lockFile, $this->pid);
             return TRUE;
         }
         $nextDelayUs = rand($this->minDelayUs, min($this->maxDelayUs, $waitUs - $totalDelayUs));
     }
     return FALSE;
 }
开发者ID:totten,项目名称:amp,代码行数:34,代码来源:PidLock.php


注:本文中的posix_getpgid函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。