/** * @param int $phpPid * @param bool testing * @return bool isChild */ public function watch($phpPid, $testing = false) { $pid = null; if ($testing == false) { $pid = pcntl_fork(); } if ($pid === -1) { throw new Exception('could not create fork for pid ' . $pid); } if ($pid && $testing == false) { pcntl_waitpid($pid, $status, WNOHANG); return $pid; } else { // child process runs what is here $this->commandLine->stdout('starting strace on pid ' . $phpPid . '.'); $result = $this->commandLine->execute($this->cmd . ' -q -s ' . $this->getLineLength() . ' -p ' . escapeshellarg($phpPid) . ' 2>&1 | tail -' . $this->getLines()); $this->commandLine->stdout('pid ' . $phpPid . ' finished running with exit code ' . $result->getReturnVar() . '.'); if ($result->getReturnVar() != 0 || substr_count(implode(' ', $result->getOutput()), self::SIGSEGV)) { foreach ($result->getOutput() as $line) { $this->commandLine->stdout($line); } } return false; } }
/** * @param $name * @return bool */ public function isProcessRunning($name) { $result = $this->commandLine->execute($this->cmd . ' xa'); foreach ($result->getOutput() as $line) { if (mb_substr_count($line, $name)) { return true; } } return false; }