• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP posix_getpgid函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: annihilateProcessGroup

 private function annihilateProcessGroup()
 {
     $pid = $this->childPID;
     $pgid = posix_getpgid($pid);
     if ($pid && $pgid) {
         // NOTE: On Ubuntu, 'kill' does not recognize the use of "--" to
         // explicitly delineate PID/PGIDs from signals. We don't actually need it,
         // so use the implicit "kill -TERM -pgid" form instead of the explicit
         // "kill -TERM -- -pgid" form.
         exec("kill -TERM -{$pgid}");
         sleep($this->killDelay);
         // On OSX, we'll get a permission error on stderr if the SIGTERM was
         // successful in ending the life of the process group, presumably because
         // all that's left is the daemon itself as a zombie waiting for us to
         // reap it. However, we still need to issue this command for process
         // groups that resist SIGTERM. Rather than trying to figure out if the
         // process group is still around or not, just SIGKILL unconditionally and
         // ignore any error which may be raised.
         exec("kill -KILL -{$pgid} 2>/dev/null");
         $this->childPID = null;
     }
 }
开发者ID:rwray,项目名称:libphutil,代码行数:22,代码来源:PhutilDaemonOverseer.php


示例17: getPid

 protected function getPid()
 {
     $pid_file = config('laravoole.base_config.pid_file');
     if (file_exists($pid_file)) {
         $pid = file_get_contents($pid_file);
         if (posix_getpgid($pid)) {
             return $pid;
         } else {
             unlink($pid_file);
         }
     }
     return false;
 }
开发者ID:acabin,项目名称:laravoole,代码行数:13,代码来源:LaravooleCommand.php


示例18: check_workers

 protected function check_workers()
 {
     foreach ($this->consumers as $key => $consumer) {
         if (posix_getpgid($consumer) === false) {
             $this->logger->addCritical("Consumer {$this->consumers_id[$consumer]} has shutdown. Restarting it");
             unset($this->consumers[$key]);
             unset($this->consumers_id[$consumer]);
             array_push($this->consumers, $this->createConsumer(count($this->consumers) + 1));
         }
     }
 }
开发者ID:brutalsys,项目名称:rmq_worker,代码行数:11,代码来源:Server.php


示例19: status

 public function status()
 {
     return posix_getpgid($this->pid) !== false;
 }
开发者ID:uafrica,项目名称:delayed-jobs,代码行数:4,代码来源:Process.php


示例20: isPIDExists

 public static function isPIDExists($pid)
 {
     return function_exists('posix_getpgid') ? posix_getpgid($pid) !== false : file_exists('/proc/' . $pid);
 }
开发者ID:Rapiddot,项目名称:ruTorrent,代码行数:4,代码来源:task.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP posix_getpid函数代码示例发布时间:2022-05-15
下一篇:
PHP posix_getgroups函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap