posix_kill($master_pid, 0) 返回false , 但其实是有这个进程的

hunterkou

当我想停止一个进程的时候, 使用参数 stop, 结果 workermanlog一直在提示Workerman not run... ,然后我就追踪代码,一直看到了这个位置。

$master_pid      = @file_get_contents(self::$pidFile);
$master_is_alive = $master_pid && @posix_kill($master_pid, 0);
 if ($master_is_alive) {
            if ($command === 'start') {
                self::log("Workerman already running...");
                exit;
            }
        } elseif ($command !== 'start' && $command !== 'restart' && $command !== 'kill') {
            
            self::log("Workerman not run...");
            exit;
        }
 

最后发现是 posix_kill($master_pid, 0)  返回false , 但明明是有这个master_pid , 而且使用 ps -ef grep  也能看到这个workerman进程。

是什么原因导致返回的false呢 ? posix_kill 这个函数有什么需要特别注意的地方吗?

2228 2 0
2个回答

six

估计是权限问题,不是root用户运行的

  • hunterkou 2019-08-30

    嗯, 不是同一个用户运行的 。所以posix_kill 是需要权限才能检测到进程?

hunterkou

嗯, 不是同一个用户运行的 。所以posix_kill 是需要权限才能检测到进程?

  • blogdaren 2019-08-30

    用什么用户start,就用什么用户stop; 或者赋予用户足够的操作权限。

  • hunterkou 2019-08-30

    @614:嗯, 我试试 多谢

年代过于久远,无法发表回答
🔝