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


PHP pcntl_wtermsig函数代码示例

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


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

示例1: start

 /**
  * Start the child processes. 
  *
  * This should only be called from the command line. It should be called 
  * as early as possible during execution.
  *
  * This will return 'child' in the child processes. In the parent process, 
  * it will run until all the child processes exit or a TERM signal is 
  * received. It will then return 'done'.
  */
 public function start()
 {
     // Trap SIGTERM
     pcntl_signal(SIGTERM, array($this, 'handleTermSignal'), false);
     do {
         // Start child processes
         if ($this->procsToStart) {
             if ($this->forkWorkers($this->procsToStart) == 'child') {
                 return 'child';
             }
             $this->procsToStart = 0;
         }
         // Check child status
         $status = false;
         $deadPid = pcntl_wait($status);
         if ($deadPid > 0) {
             // Respond to child process termination
             unset($this->children[$deadPid]);
             if ($this->flags & self::RESTART_ON_ERROR) {
                 if (pcntl_wifsignaled($status)) {
                     // Restart if the signal was abnormal termination
                     // Don't restart if it was deliberately killed
                     $signal = pcntl_wtermsig($status);
                     if (in_array($signal, self::$restartableSignals)) {
                         echo "Worker exited with signal {$signal}, restarting\n";
                         $this->procsToStart++;
                     }
                 } elseif (pcntl_wifexited($status)) {
                     // Restart on non-zero exit status
                     $exitStatus = pcntl_wexitstatus($status);
                     if ($exitStatus > 0) {
                         echo "Worker exited with status {$exitStatus}, restarting\n";
                         $this->procsToStart++;
                     }
                 }
             }
             // Throttle restarts
             if ($this->procsToStart) {
                 usleep(500000);
             }
         }
         // Run signal handlers
         if (function_exists('pcntl_signal_dispatch')) {
             pcntl_signal_dispatch();
         } else {
             declare (ticks=1) {
                 $status = $status;
             }
         }
         // Respond to TERM signal
         if ($this->termReceived) {
             foreach ($this->children as $childPid => $unused) {
                 posix_kill($childPid, SIGTERM);
             }
             $this->termReceived = false;
         }
     } while (count($this->children));
     pcntl_signal(SIGTERM, SIG_DFL);
     return 'done';
 }
开发者ID:ruizrube,项目名称:spdef,代码行数:70,代码来源:ForkController.php

示例2: pleac_Running_Another_Program

function pleac_Running_Another_Program()
{
    // Run a simple command and retrieve its result code.
    exec("vi {$myfile}", $output, $result_code);
    // -----------------------------
    // Use the shell to perform redirection.
    exec('cmd1 args | cmd2 | cmd3 >outfile');
    exec('cmd args <infile >outfile 2>errfile');
    // -----------------------------
    // Run a command, handling its result code or signal.
    $pid = pcntl_fork();
    if ($pid == -1) {
        die('cannot fork');
    } elseif ($pid) {
        pcntl_waitpid($pid, $status);
        if (pcntl_wifexited($status)) {
            $status = pcntl_wexitstatus($status);
            echo "program exited with status {$status}\n";
        } elseif (pcntl_wifsignaled($status)) {
            $signal = pcntl_wtermsig($status);
            echo "program killed by signal {$signal}\n";
        } elseif (pcntl_wifstopped($status)) {
            $signal = pcntl_wstopsig($status);
            echo "program stopped by signal {$signal}\n";
        }
    } else {
        pcntl_exec($program, $args);
    }
    // -----------------------------
    // Run a command while blocking interrupt signals.
    $pid = pcntl_fork();
    if ($pid == -1) {
        die('cannot fork');
    } elseif ($pid) {
        // parent catches INT and berates user
        declare (ticks=1);
        function handle_sigint($signal)
        {
            echo "Tsk tsk, no process interruptus\n";
        }
        pcntl_signal(SIGINT, 'handle_sigint');
        while (!pcntl_waitpid($pid, $status, WNOHANG)) {
        }
    } else {
        // child ignores INT and does its thing
        pcntl_signal(SIGINT, SIG_IGN);
        pcntl_exec('/bin/sleep', array('10'));
    }
    // -----------------------------
    // Since there is no direct access to execv() and friends, and
    // pcntl_exec() won't let us supply an alternate program name
    // in the argument list, there is no way to run a command with
    // a different name in the process table.
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:54,代码来源:Running_Another_Program.php

示例3: __construct

 /**
  * Analyzes the passed status code of a process and sets properties accordingly.
  * 
  * @param int $status
  * @author Dan Homorodean <dan.homorodean@gmail.com>
  */
 public function __construct($status)
 {
     if (pcntl_wifexited($status)) {
         $this->status = self::STATUS_EXITED;
         $this->exitCode = pcntl_wexitstatus($status);
     } elseif (pcntl_wifsignaled($status)) {
         $this->status = self::STATUS_SIGNALED;
         $this->reasonSignal = pcntl_wtermsig($status);
     } elseif (pcntl_wifstopped($status)) {
         $this->status = self::STATUS_STOPPED;
         $this->reasonSignal = pcntl_wstopsig($status);
     }
 }
开发者ID:dan-homorodean,项目名称:falx-concurrency-and-ipc,代码行数:19,代码来源:ProcessStatus.php

示例4: test_exit_signal

function test_exit_signal()
{
    print "\n\nTesting pcntl_wifsignaled....";
    $pid = pcntl_fork();
    if ($pid == 0) {
        sleep(10);
        exit;
    } else {
        $options = 0;
        posix_kill($pid, SIGTERM);
        pcntl_waitpid($pid, $status, $options);
        if (pcntl_wifsignaled($status)) {
            $signal_print = pcntl_wtermsig($status);
            if ($signal_print == SIGTERM) {
                $signal_print = "SIGTERM";
            }
            print "\nProcess was terminated by signal : " . $signal_print;
        }
    }
}
开发者ID:badlamer,项目名称:hhvm,代码行数:20,代码来源:001.php

示例5: handleIOError

 /**
  * @throws ScribuntoException
  */
 protected function handleIOError()
 {
     $this->checkValid();
     proc_terminate($this->proc);
     $wstatus = proc_close($this->proc);
     $signaled = pcntl_wifsignaled($wstatus);
     $termsig = pcntl_wtermsig($wstatus);
     $exitcode = pcntl_wexitstatus($wstatus);
     $this->proc = false;
     if ($signaled) {
         if (defined('SIGXCPU') && $termsig == SIGXCPU) {
             $this->exitError = $this->engine->newException('scribunto-common-timeout');
         } else {
             $this->exitError = $this->engine->newException('scribunto-luastandalone-signal', array('args' => array($termsig)));
         }
     } else {
         $this->exitError = $this->engine->newException('scribunto-luastandalone-exited', array('args' => array($exitcode)));
     }
     throw $this->exitError;
 }
开发者ID:sammykumar,项目名称:TheVRForums,代码行数:23,代码来源:LuaStandaloneEngine.php

示例6: updateStatus

 /**
  * update the process status
  * @param bool $block
  */
 public function updateStatus($block = false)
 {
     if (empty($this->pid)) {
         $message = "the process pid is null, so maybe the process is not started";
         throw new \RuntimeException($message);
     }
     if ($this->running === false) {
         return;
     }
     if ($block) {
         $res = pcntl_waitpid($this->pid, $status);
     } else {
         $res = pcntl_waitpid($this->pid, $status, WNOHANG | WUNTRACED);
     }
     if ($res === -1) {
         $message = "pcntl_waitpid failed. the process maybe available";
         throw new \RuntimeException($message);
     } elseif ($res === 0) {
         $this->running = true;
     } else {
         if (pcntl_wifsignaled($status)) {
             $this->term_signal = pcntl_wtermsig($status);
         }
         if (pcntl_wifstopped($status)) {
             $this->stop_signal = pcntl_wstopsig($status);
         }
         if (pcntl_wifexited($status)) {
             $this->exit_code = pcntl_wexitstatus($status);
         } else {
             $this->errno = pcntl_get_last_error();
             $this->errmsg = pcntl_strerror($this->errno);
         }
         $this->running = false;
     }
 }
开发者ID:jzxyouok,项目名称:simple-fork-php,代码行数:39,代码来源:Process.php

示例7: pcntl_fork

$pid = pcntl_fork();
if ($pid == 0) {
    exit(0x12);
}
pcntl_waitpid(0, $status);
VERIFY(pcntl_wifexited($status));
$pid = pcntl_fork();
if ($pid == 0) {
    exit(0x12);
}
pcntl_waitpid(0, $status);
VERIFY(!pcntl_wifsignaled($status));
$pid = pcntl_fork();
if ($pid == 0) {
    exit(0x12);
}
pcntl_waitpid(0, $status);
VERIFY(!pcntl_wifstopped($status));
$pid = pcntl_fork();
if ($pid == 0) {
    exit(0x12);
}
pcntl_waitpid(0, $status);
VS(pcntl_wstopsig($status), 0x12);
$pid = pcntl_fork();
if ($pid == 0) {
    exit(0x12);
}
pcntl_waitpid(0, $status);
VS(pcntl_wtermsig($status), 0);
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:ext_process.php

示例8: wTermSig

 /**
  * W Term Sig
  *
  * @param $status The status parameter is the status parameter supplied to a successful call to pcntl_waitpid().
  *
  * @return int Returns the signal number, as an integer.
  */
 public function wTermSig($status)
 {
     return pcntl_wtermsig($status);
 }
开发者ID:dantudor,项目名称:pcntl,代码行数:11,代码来源:Pcntl.php

示例9: getTerminateSignal

 /**
  * Returns the signal which caused the child to terminate.
  *
  * @return int
  */
 public function getTerminateSignal()
 {
     return pcntl_wtermsig($this->status);
 }
开发者ID:jamiefifty,项目名称:Process,代码行数:9,代码来源:Status.php

示例10: processSignalChild

 private function processSignalChild()
 {
     $childrenQty = 0;
     while (true) {
         $exitedWorkerPid = pcntl_waitpid(-1, $status, WNOHANG);
         if ($exitedWorkerPid === 0) {
             Logger::getLogger('queue')->debug("process SIGCHLD complete, childrenQty={$childrenQty}");
             return;
         }
         if ($exitedWorkerPid === -1) {
             $error_number = pcntl_get_last_error();
             $error = "[{$error_number}] " . pcntl_strerror($error_number);
             $message = "Can't wait pid, error: '{$error}'";
             if ($error_number === PCNTL_ECHILD) {
                 Logger::getLogger('queue')->debug($message);
             } else {
                 Logger::getLogger('queue')->error($message);
             }
             return;
         }
         Logger::getLogger('queue')->debug("exitedWorkerPid={$exitedWorkerPid}");
         if (!isset($this->childrenInfo[$exitedWorkerPid])) {
             Logger::getLogger('queue')->error('pcntl_waitpid return unknown pid:' . var_export($exitedWorkerPid, true), new Exception());
             continue;
         }
         $isExited = false;
         $queueNick = $this->childrenInfo[$exitedWorkerPid]['queueNick'];
         if (pcntl_wifexited($status)) {
             $isExited = true;
             $code = pcntl_wexitstatus($status);
             Logger::getLogger('queue')->debug("exitCode={$code}");
             if (!isset($this->workersErrorsQty[$queueNick])) {
                 $this->workersErrorsQty[$queueNick] = 0;
             }
             if ($code) {
                 ++$this->workersErrorsQty[$queueNick];
                 Logger::getLogger('queue')->error("worker pid={$exitedWorkerPid} for queue {$queueNick} exit with code {$code}");
             } else {
                 $this->workersErrorsQty[$queueNick] = 0;
             }
             if ($this->workersErrorsQty[$queueNick] > $this->maxWorkersQty * 0.5) {
                 $message = "queue {$queueNick} worker errors qty = {$this->workersErrorsQty[$queueNick]}. Disable this queue.";
                 $this->queuesInfo[$queueNick]['state'] = 'error';
                 $this->queuesInfo[$queueNick]['message'] = $message;
                 Logger::getLogger('queue')->error($message);
                 if (isset($this->queues[$queueNick])) {
                     $this->queues[$queueNick]->unlockTasks();
                     unset($this->queues[$queueNick]);
                 }
             }
         }
         if (pcntl_wifsignaled($status)) {
             $isExited = true;
             $errorSignal = pcntl_wtermsig($status);
             Logger::getLogger('queue')->error("{$exitedWorkerPid} terminate by signal {$errorSignal}");
         }
         if (pcntl_wifstopped($status)) {
             $stopSignal = pcntl_wstopsig($status);
             Logger::getLogger('queue')->error("{$exitedWorkerPid} stop by signal {$stopSignal}");
         }
         if ($isExited) {
             --$this->workersQty;
             if (isset($this->queuesInfo[$queueNick])) {
                 --$this->queuesInfo[$queueNick]['activeWorkersQty'];
                 Logger::getLogger('queue')->debug("worker complete, workersQty={$this->workersQty},queue={$queueNick},activeWorkersQty={$this->queuesInfo[$queueNick]['activeWorkersQty']}");
             }
             $this->freeWorkersNumbers[] = $this->childrenInfo[$exitedWorkerPid]['workerNumber'];
             unset($this->childrenInfo[$exitedWorkerPid]);
         }
         ++$childrenQty;
     }
 }
开发者ID:mailru,项目名称:queue-processor,代码行数:72,代码来源:Processor.php

示例11: while

        }
    }
    while (true) {
        $pid = pcntl_waitpid(-1, $status, WNOHANG | WUNTRACED);
        if ($pid === 0) {
            echo "No children exited\n";
            break;
        } elseif ($pid === -1) {
            echo "Failed something\n";
            echo "Status '" . $status . "'\n";
            if (pcntl_wifexited($status)) {
                echo "pcntl_wifexited\n";
            } elseif (pcntl_wifstopped($status)) {
                echo "pcntl_wifstopped\n";
            } elseif (pcntl_wifsignaled($status)) {
                echo "pcntl_wifsignaled\n";
            } elseif (pcntl_wexitstatus($status)) {
                echo " pcntl_wexitstatus\n";
            } elseif (pcntl_wtermsig($status)) {
                echo " pcntl_wtermsig\n";
            } elseif (pcntl_wstopsig($status)) {
                echo " pcntl_wstopsig\n";
            }
            exit;
        } else {
            echo "Child #" . $pid . " exited\n";
            $exit = true;
        }
    }
    sleep(1);
}
开发者ID:gcds,项目名称:morker,代码行数:31,代码来源:sandbox.php

示例12: supervise

 /**
  * Supervise the children and react on finished processes.
  *
  * @param callback $ticker callback to call during each loop
  */
 public function supervise($ticker = NULL, $respawnChecker = NULL)
 {
     // loop and monitor children
     while (!empty($this->children)) {
         $start = time();
         // Check if a child exited
         foreach ($this->children as $pid => $fork) {
             $exited = pcntl_waitpid($pid, $status, WNOHANG);
             switch ($exited) {
                 case $pid:
                     $fork->setStop();
                     unset($this->children[$pid]);
                     switch (TRUE) {
                         // signal which was not caught
                         case pcntl_wifsignaled($status):
                             self::log(sprintf('Child %d, %s terminated from signal %d after running %d seconds.', $pid, $fork->description, pcntl_wtermsig($status), $fork->getDurationSeconds()), ezcLog::INFO);
                             break;
                         case pcntl_wifexited($status):
                             $exitstatus = pcntl_wexitstatus($status);
                             self::log(sprintf('Child %d, %s exited with status %d after running %d seconds.', $pid, $fork->description, $exitstatus, $fork->getDurationSeconds()), ezcLog::INFO);
                             //@TODO make reforking configurable
                             $respawn = $this->respawn;
                             if ($respawn && is_callable($respawnChecker)) {
                                 $respawn = call_user_func($respawnChecker, $pid, $exitstatus);
                             }
                             if ($respawn) {
                                 self::log('refork ' . $fork->description, ezcLog::INFO);
                                 $this->fork($fork);
                             }
                             break;
                         case pcntl_wifstopped($status):
                             self::log(sprintf('Child %d, %s stopped from signal %d after running %d seconds.', $pid, $fork->description, pcntl_wstopsig($status), $fork->getDurationSeconds()), ezcLog::INFO);
                             break;
                     }
                     break;
                 case -1:
                     self::log(sprintf('Got -1 when checking pid %d', $pid), ezcLog::ERROR);
                     break;
                 case 0:
                     break;
                 default:
                     throw new Exception('pcntl_waitpid returned ' . $exited . ' for pid ' . $pid);
             }
         }
         // save CPU cycles
         // sleep( 5 );
         $this->runServer();
         if (is_callable($ticker)) {
             call_user_func($ticker);
         }
         self::log(sprintf('fork runner supervise loop took %d seconds.', time() - $start), ezcLog::DEBUG);
     }
     self::log('Leaving fork runner supervise function', ezcLog::DEBUG);
 }
开发者ID:jou,项目名称:ymc-components,代码行数:59,代码来源:fork_runner.php

示例13: wait

 /**
  * Wait for all child processes to complete
  */
 public function wait()
 {
     // Wait for all children to return
     foreach ($this->child_pid_list as $child_pid) {
         if (pcntl_waitpid($child_pid, $status) < 0) {
             error_log(posix_strerror(posix_get_last_error()));
         }
         // Check to see if the child died a graceful death
         $status = 0;
         if (pcntl_wifsignaled($status)) {
             $return_code = pcntl_wexitstatus($status);
             $term_sig = pcntl_wtermsig($status);
             error_log("Child terminated with return code {$return_code} and signal {$term_sig}");
         }
     }
 }
开发者ID:ablyler,项目名称:phan,代码行数:19,代码来源:ForkPool.php

示例14: watchdogProcessStatus

 /**
  * @param $status
  *
  * @return bool
  */
 private function watchdogProcessStatus($status)
 {
     switch (true) {
         case pcntl_wifexited($status):
             $code = pcntl_wexitstatus($status);
             $this->handleProcessExitStatus($this->watchdogPID, self::PROCESS_TYPE_WATCHDOG, $code);
             return true;
         case pcntl_wifsignaled($status):
             $sig = pcntl_wtermsig($status);
             if ($sig !== SIGKILL) {
                 $this->logger->warn(sprintf("watchdog %d terminated with unhandled signal %s\n", $this->watchdogPID, pcntl_sig_name($sig)));
             }
             return true;
         case pcntl_wifstopped($status):
             $sig = pcntl_wstopsig($status);
             $this->logger->warn(sprintf("watchdog %d was stopped with signal %s\n", $this->watchdogPID, pcntl_sig_name($sig)));
             return false;
         default:
             $this->logger->error(sprintf("unexpected status for watchdog %d; exiting\n", $this->childPID));
             exit(1);
     }
 }
开发者ID:contatta,项目名称:qless-php,代码行数:27,代码来源:Worker.php

示例15: getExitSignalNo

 /**
  * Returns the signal which caused the child to terminate
  *
  * @param int $status The status parameter is the status parameter supplied to a successful call to pcntl_waitpid().
  *
  * @return int Returns the signal number, as an integer.
  */
 public function getExitSignalNo(int $status) : int
 {
     return pcntl_wtermsig($status);
 }
开发者ID:aurimasniekis,项目名称:thruster,代码行数:11,代码来源:ProcessControl.php


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