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

PHP posix_kill函数代码示例

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

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



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

示例1: acquire

 /**
  * Creates a lock file for the given name.
  *
  * @param   string $name The name of this lock file
  * @param   bool $check If we should check if the process exists in addition to check for a lock file
  * @return  boolean
  */
 public static function acquire($name, $check = false)
 {
     $pid = self::getProcessID($name);
     if (!empty($pid)) {
         // Test asks us to check if the process is still running
         if ($check) {
             if (function_exists('posix_kill')) {
                 $exists = posix_kill($pid, 0);
             } else {
                 $retval = 0;
                 $out = array();
                 exec('kill -s 0 ' . $pid, $out, $retval);
                 $exists = $retval == 0;
             }
             if ($exists) {
                 return false;
             }
         }
         return false;
     }
     // create the pid file
     $fp = fopen(self::getProcessFilename($name), 'w');
     flock($fp, LOCK_EX);
     fwrite($fp, getmypid());
     flock($fp, LOCK_UN);
     fclose($fp);
     return true;
 }
开发者ID:korusdipl,项目名称:eventum,代码行数:35,代码来源:class.lock.php


示例2: CheckDaemon

 private function CheckDaemon()
 {
     if ($pidfile = @fopen($this->pidfile_path, "r")) {
         $pid_daemon = fgets($pidfile, 20);
         fclose($pidfile);
         $pid_daemon = (int) $pid_daemon;
         // bad PID file, e.g. due to system malfunction while creating the file?
         if ($pid_daemon <= 0) {
             echo "removing bad pid_file (" . $this->pidfile_path . ")\n";
             unlink($this->pidfile_path);
             return false;
         } elseif (posix_kill($pid_daemon, 0)) {
             // yes, good bye
             echo "Error: process for " . $this->pidfile_path . " is already running with pid={$pid_daemon}\n";
             return false;
         } else {
             // no, remove pid_file
             echo "process not running, removing old pid_file (" . $this->pidfile_path . ")\n";
             unlink($this->pidfile_path);
             return true;
         }
     } else {
         return true;
     }
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:25,代码来源:ProcessSync.class.php


示例3: dealMission

 /**
  * 多进程处理任务
  * @param callback  $mission_func 子进程要进行的任务函数
  */
 public function dealMission($mission_func)
 {
     $this->_mission_func = $mission_func;
     for ($i = 0; $i < $this->_process_num; $i++) {
         $pid[] = pcntl_fork();
         if ($pid[$i] == 0) {
             //等于0时,是子进程
             $this->_func_obj->{$mission_func}($i + 1);
             //结束当前子进程,以防止生成僵尸进程
             if (function_exists("posix_kill")) {
                 posix_kill(getmypid(), SIGTERM);
             } else {
                 system('kill -9' . getmypid());
             }
             exit;
         } else {
             if ($pid > 0) {
                 //大于0时,是父进程,并且pid是产生的子进程的PID
                 //TODO 可以记录下子进程的pid,用pcntl_wait_pid()去等待程序并结束
                 pcntl_wait($status);
             } else {
                 throw new Exception('fork fail');
             }
         }
     }
 }
开发者ID:xxlixin1993,项目名称:spider,代码行数:30,代码来源:Process.php


示例4: stopDownload

 public function stopDownload()
 {
     $wget_pid = $this->_get_wget_pid($_localImagePath);
     if ($wget_pid != -1) {
         posix_kill($wget_pid, SIGKILL);
     }
 }
开发者ID:gremilkar,项目名称:netaidkit,代码行数:7,代码来源:Updater.php


示例5: killChildProcesses

 /**
  * Kills all running child-processes
  */
 public function killChildProcesses()
 {
     $child_pids = $this->getChildPIDs();
     for ($x = 0; $x < count($child_pids); $x++) {
         posix_kill($child_pids[$x], SIGKILL);
     }
 }
开发者ID:haythameyd,项目名称:socialfp,代码行数:10,代码来源:PHPCrawlerProcessHandler.class.php


示例6: execute

 public final function execute()
 {
     $hasThreads = function_exists('pcntl_signal');
     if (!$hasThreads || Cli::getInstance()->isSimulation()) {
         flush();
         try {
             return $this->executeNoThread();
         } catch (Interrupt $e) {
             throw $e;
         } catch (Exception $e) {
             echo $e;
         }
         return;
     }
     pcntl_signal(SIGCHLD, SIG_IGN);
     $pid = pcntl_fork();
     if ($pid < 1) {
         $this->_run();
         posix_kill(posix_getpid(), 9);
         pcntl_waitpid(posix_getpid(), $temp = 0, WNOHANG);
         pcntl_wifexited($temp);
         exit;
         //Make sure we exit...
     } else {
         $this->pid = $pid;
     }
 }
开发者ID:hofmeister,项目名称:Pimple,代码行数:27,代码来源:Thread.php


示例7: killProcess

 /**
  * @param string                  $pidPath
  * @param bool                    $throwException
  * @param LoggerInterface         $logger
  * @param LOLClientInterface|null $client
  *
  * @throws \RuntimeException
  */
 public static function killProcess($pidPath, $throwException, LoggerInterface $logger, LOLClientInterface $client = null)
 {
     $pid = (int) file_get_contents($pidPath);
     // Test if process is still running
     $output = [];
     exec('ps ' . $pid, $output);
     if (!isset($output[1])) {
         if (null != $client) {
             $logger->debug('Client ' . $client . ' (pid: #' . $pid . ') not running, deleting cache pid file');
         } else {
             $logger->debug('Process #' . $pid . ' not running, deleting cache pid file');
         }
         unlink($pidPath);
         return;
     }
     // Kill
     if (posix_kill($pid, SIGKILL)) {
         if (null != $client) {
             $logger->debug('Client ' . $client . ' (pid: #' . $pid . ') has been killed');
         } else {
             $logger->debug('Process #' . $pid . ' has been killed');
         }
         unlink($pidPath);
     } else {
         if ($throwException) {
             throw new \RuntimeException('Cannot kill the process #' . $pid . ', please kill this process manually');
         }
         $logger->critical('Cannot kill the process #' . $pid . ', please kill this process manually');
     }
 }
开发者ID:phxlol,项目名称:lol-php-api,代码行数:38,代码来源:Process.php


示例8: sig_handler

function sig_handler($signo)
{
    $log = getLog('queue/queued');
    $log->setData("\r\n" . 'Signal Receive:' . $signo . ' ' . date('Y-m-d H:i:s'));
    $pids = @file(ROOT . 'logs/queue/pids');
    if (is_array($pids)) {
        foreach ($pids as $pid) {
            list(, , $pid) = explode('_', $pid);
            if (!empty($pid)) {
                $pid = intval($pid);
                @posix_kill($pid, SIGTERM);
                if (file_exists(ROOT . 'logs/queue/pid/' . $pid)) {
                    @unlink(ROOT . 'logs/queue/pid/' . $pid);
                }
            }
        }
    }
    switch ($signo) {
        case SIGHUP:
            @popen(ROOT . 'daemon/queue/queued.php 2>&1 > /dev/null &', "r");
            break;
    }
    $log->setData("\r\n" . 'Signal Process Finished:' . date('Y-m-d H:i:s'))->write();
    exit;
}
开发者ID:roast,项目名称:queued,代码行数:25,代码来源:queued.php


示例9: stop

 public function stop()
 {
     if (!$this->process) {
         return;
     }
     $status = proc_get_status($this->process);
     if ($status['running']) {
         fclose($this->pipes[1]);
         //stdout
         fclose($this->pipes[2]);
         //stderr
         //get the parent pid of the process we want to kill
         $pPid = $status['pid'];
         //use ps to get all the children of this process, and kill them
         foreach (array_filter(preg_split('/\\s+/', `ps -o pid --no-heading --ppid {$pPid}`)) as $pid) {
             if (is_numeric($pid)) {
                 posix_kill($pid, 9);
                 // SIGKILL signal
             }
         }
     }
     fclose($this->pipes[0]);
     proc_terminate($this->process);
     $this->process = NULL;
 }
开发者ID:kdyby,项目名称:selenium,代码行数:25,代码来源:VideoRecorder.php


示例10: stopServer

 /**
  * Stop the jackrabbit server. If it is not running, silently return.
  */
 public function stopServer()
 {
     $pid = $this->getServerPid();
     if ($pid) {
         posix_kill($pid, SIGKILL);
     }
 }
开发者ID:Alfusainey,项目名称:jackalope-jackrabbit,代码行数:10,代码来源:JackrabbitHelper.php


示例11: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $id = $input->getArgument('id');
     // Do a cleanup
     $worker = new Resque\Worker('*');
     $worker->cleanup();
     if ($id) {
         if (false === ($worker = Resque\Worker::hostWorker($id))) {
             $this->log('There is no worker with id "' . $id . '".', Resque\Logger::ERROR);
             return;
         }
         $workers = array($worker);
     } else {
         $workers = Resque\Worker::hostWorkers();
     }
     if (!count($workers)) {
         $this->log('<warn>There are no workers on this host</warn>');
     }
     foreach ($workers as $worker) {
         $packet = $worker->getPacket();
         $job_pid = (int) $packet['job_pid'];
         if ($job_pid and posix_kill($job_pid, 0)) {
             if (posix_kill($job_pid, SIGUSR1)) {
                 $this->log('Worker <pop>' . $worker . '</pop> running job SIGUSR1 signal sent.');
             } else {
                 $this->log('Worker <pop>' . $worker . '</pop> <error>running job SIGUSR1 signal could not be sent.</error>');
             }
         } else {
             $this->log('Worker <pop>' . $worker . '</pop> has no running job.');
         }
     }
 }
开发者ID:mjphaynes,项目名称:php-resque,代码行数:32,代码来源:Cancel.php


示例12: getTestCaseClosure

/**
 * @param $strTestFile         - the file to check for test-cases
 * @param $arrDefinedFunctions - all user-definied functions until now
 * @param $intParentPID        - the process-pid of the parent
 * 
 * @throw \Exception - if first parameter is not a string
 * @throw \Exception - if given file is not a file nor readable
 * @throw \Exception - if given parent-id is not an integer
 *
 * create a closure for execution in a fork. it will: 
 * - include the given test-file
 * - find test-cases definied in test-file
 * - send list of test-cases to queue
 * - send SIGTERM to parent id and exit
 *
 **/
function getTestCaseClosure($strTestFile, array $arrDefinedFunctions, $intParentPID)
{
    if (!is_string($strTestFile)) {
        throw new \Exception("first given parameter is not a string");
    }
    if (!is_file($strTestFile) || !is_readable($strTestFile)) {
        throw new \Exception("given file is not a file or not readable: {$strTestFile}");
    }
    if (!is_int($intParentPID)) {
        throw new \Exception("third given parameter is not an integer");
    }
    return function () use($strTestFile, $arrDefinedFunctions, $intParentPID) {
        include $strTestFile;
        # get test-cases
        $arrAllFunctions = get_defined_functions();
        $arrUserFunctions = $arrAllFunctions['user'];
        $arrDefinedFunctions = array_diff($arrUserFunctions, $arrDefinedFunctions);
        $arrTestCases = array();
        foreach ($arrDefinedFunctions as $strFunction) {
            if (fnmatch('aphpunit\\testcases\\test*', $strFunction, FNM_NOESCAPE)) {
                $arrTestCases[] = $strFunction;
            }
        }
        # collect all information in this structure
        $arrMsgContent = array('file' => $strTestFile, 'functions' => $arrTestCases);
        # send the result to the queue
        $objQueue = new \SimpleIPC(QUEUE_IDENTIFIER);
        $objQueue->send(serialize($arrMsgContent));
        # kill thread after sending parent a SIGTERM
        posix_kill($intParentPID, SIGTERM);
        exit;
    };
}
开发者ID:t-zuehlsdorff,项目名称:asap,代码行数:49,代码来源:getTestCaseClosure.inc.php


示例13: testRunningDaemonWithResistingWorker

 public function testRunningDaemonWithResistingWorker()
 {
     $writer = $this->getFileWriter();
     $fork = $this->outerManager->fork(function () use($writer) {
         $handler = new NullHandler();
         $builder = new Builder(array('worker1' => function () use($writer) {
             $writer("worker1.call");
         }, 'worker2' => array('startup' => function () use($writer) {
             pcntl_signal(SIGQUIT, SIG_IGN);
             pcntl_signal(SIGINT, SIG_IGN);
             $writer("worker2.startup");
         }, 'loop' => function () use($writer) {
             $writer("worker2.call");
         }, 'interval' => 1)));
         $builder->setLogger(new Logger('test', array($handler)))->setShutdownTimeout(3);
         $daemon = $builder->build();
         $daemon->setProcessName('testing');
         $daemon->run();
     });
     sleep(1);
     $start = time();
     $fork->kill(SIGQUIT);
     while (posix_kill($fork->getPid(), 0)) {
         pcntl_waitpid($fork->getPid(), $status, WNOHANG | WUNTRACED);
         usleep(100000);
     }
     $end = time();
     $diff = $end - $start;
     $this->assertTrue($diff >= 2 && $diff <= 4, 'Has been killed in shutdown interval');
     $content = file_get_contents($this->tempFile);
     $this->assertSame(1, preg_match_all('/worker1\\.call/', $content));
     $this->assertSame(1, preg_match_all('/worker2\\.startup/', $content));
     $calls = preg_match_all('/worker2\\.call/', $content);
     $this->assertTrue($calls >= 3 && $calls <= 5, 'Expected amount of worker2 calls');
 }
开发者ID:fortrabbit,项目名称:beelzebub,代码行数:35,代码来源:RunDaemonTest.php


示例14: killAll

 public function killAll()
 {
     /** @var \Aurora\Worker $worker */
     foreach ($this->workers as $worker) {
         posix_kill($worker->getPid(), SIGKILL);
     }
 }
开发者ID:panlatent,项目名称:aurora,代码行数:7,代码来源:WorkerManager.php


示例15: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $id = $input->getArgument('id');
     // Do a cleanup
     $worker = new Resque\Worker('*');
     $worker->cleanup();
     if ($id) {
         if (false === ($worker = Resque\Worker::hostWorker($id))) {
             $this->log('There is no worker with id "' . $id . '".', Resque\Logger::ERROR);
             return;
         }
         $workers = array($worker);
     } else {
         $workers = Resque\Worker::hostWorkers();
     }
     if (!count($workers)) {
         $this->log('<warn>There are no workers on this host</warn>');
     }
     $sig = $input->getOption('force') ? 'TERM' : 'QUIT';
     foreach ($workers as $worker) {
         if (posix_kill($worker->getPid(), constant('SIG' . $sig))) {
             $this->log('Worker <pop>' . $worker . '</pop> ' . $sig . ' signal sent.');
         } else {
             $this->log('Worker <pop>' . $worker . '</pop> <error>could not send ' . $sig . ' signal.</error>');
         }
     }
 }
开发者ID:mjphaynes,项目名称:php-resque,代码行数:27,代码来源:Stop.php


示例16: killAllProcesses

 /**
  * Sends the kill signal to all processes and removes them from the list.
  *
  * @return void
  */
 public function killAllProcesses()
 {
     foreach ($this->processDetails as $pid => $processDetails) {
         $this->remove($processDetails);
         posix_kill($pid, SIGKILL);
     }
 }
开发者ID:KevenLibcast,项目名称:WorkerPool,代码行数:12,代码来源:ProcessDetailsCollection.php


示例17: handleStop

 protected function handleStop()
 {
     $pidFile = APPLICATION_PATH . '/runtime/jobserver.pid';
     if (file_exists($pidFile)) {
         $pids = explode("|", file_get_contents($pidFile));
         $del = 1;
         foreach ($pids as $pid) {
             $rs = posix_kill($pid, 15);
             if (!$rs) {
                 $del = 0;
                 echo "del_fail\r\n";
                 print_r(posix_get_last_error());
                 echo "\r\n";
             }
         }
         if ($del) {
             echo "del_ok\r\n";
             print_r(posix_get_last_error());
             echo "\r\n";
             do {
                 unlink($pidFile);
                 usleep(100000);
             } while (file_exists($pidFile));
             return 0;
         }
     }
     return 1;
 }
开发者ID:kerisy,项目名称:framework,代码行数:28,代码来源:JobServerCommand.php


示例18: start

 /**
  * Start the task manager
  *
  * @param AbstractTask $task Task to start
  *
  * @return void
  */
 public function start(AbstractTask $task)
 {
     $pid = pcntl_fork();
     if ($pid == -1) {
         throw new \Exception('[Pid:' . getmypid() . '] Could not fork process');
     } elseif ($pid) {
         $this->_activeThreads[$pid] = true;
         // Reached maximum number of threads allowed
         if ($this->maxThreads == count($this->_activeThreads)) {
             // Parent Process : Checking all children have ended (to avoid zombie / defunct threads)
             while (!empty($this->_activeThreads)) {
                 $endedPid = pcntl_wait($status);
                 if (-1 == $endedPid) {
                     $this->_activeThreads = array();
                 }
                 unset($this->_activeThreads[$endedPid]);
             }
         }
     } else {
         $task->initialize();
         // On success
         if ($task->process()) {
             $task->onSuccess();
         } else {
             $task->onFailure();
         }
         posix_kill(getmypid(), 9);
     }
     pcntl_wait($status, WNOHANG);
 }
开发者ID:xingcuntian,项目名称:PHP-Multithread,代码行数:37,代码来源:Multiple.php


示例19: run

 public function run()
 {
     $count = 0;
     $socket = stream_socket_server($this->socketString, &$errno, &$errstr);
     if (!$socket) {
         throw new RuntimeException($errstr);
     }
     while (true) {
         while (count($this->children) < $this->maxConnections) {
             $count++;
             $pid = pcntl_fork();
             if ($pid == -1) {
                 throw new RuntimeException('Couldn\'t fork');
             } elseif ($pid == 0) {
                 $this->createChild($socket, $count);
                 exit;
             }
             $this->children[] = $pid;
         }
         while (pcntl_wait($status, WNOHANG or WUNTRACED) > 0) {
             usleep(500000);
         }
         while (list($key, $val) = each($this->children)) {
             if (!posix_kill($val, 0)) {
                 unset($this->children[$key]);
             }
         }
         $this->children = array_values($this->children);
         usleep(500000);
     }
 }
开发者ID:googlecode-mirror,项目名称:ultramilk,代码行数:31,代码来源:UltraMilk.php


示例20: _terminate

 /**
  * Terminate current process
  * 
  * @param int $timeout
  * @param int $signal
  */
 protected function _terminate($timeout = 10, $signal = 15)
 {
     foreach ($this->_getPidRecursive($this->getPid()) as $pid) {
         posix_kill($pid, $signal);
     }
     parent::stop($timeout, $signal);
 }
开发者ID:imsamurai,项目名称:cakephp-task-plugin,代码行数:13,代码来源:TaskProcess.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP posix_mkfifo函数代码示例发布时间:2022-05-15
下一篇:
PHP posix_isatty函数代码示例发布时间: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