0

谁能解释我如何从以 ssh2_exec 开始的进程中检索 ProcessID?我已经尝试了很多东西,但它只给出以下消息“资源 id #6”

下面是我正在努力解决的代码但是我没有回显 ProcessID 我只得到“资源 id #6”

$pid = ssh2_exec($connection, 'cd /home/servers/; nohup ./sc_serv' .$config .' & > /dev/null 2>&1 & echo $!');
4

3 回答 3

0

这将帮助您找到进程 ID

<?php

//this will return the process id
$pid = getmypid();

//you can check the process id
if(file_exists('/proc/'.$pid))
{
    echo 'The process is still running.';
}
于 2013-12-16T05:46:50.223 回答
0

我认为应该是:

$pid = ssh2_exec($connection, 'cd /home/servers/; nohup ./sc_serv' .$config .' & > /dev/null 2>&1; echo $!');
于 2013-12-16T06:08:48.257 回答
0

要获取通过 ssh2_exec 在远程机器上启动的进程的进程 ID,您可以执行以下操作:

$cmd = "cd /home/servers/; nohup ./sc_serv' .$config .' & > /dev/null 2>&1 & echo $!"
$stdout_stream = ssh2_exec($connection, $cmd);
$dio_stream = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
stream_set_blocking($dio_stream, true);
$pid = stream_get_contents($dio_stream);
于 2015-10-07T20:17:17.193 回答