Php 如何检索ssh2_exec进程的ProcessID
谁能解释一下如何从一个用ssh2\u exec启动的进程中检索ProcessID?我尝试了很多方法,但它只给出了以下消息“资源id#6” 下面是我正在努力处理的代码,但是没有回显ProcessID,我只得到了“Resource id#6”Php 如何检索ssh2_exec进程的ProcessID,php,libssh2,pid,Php,Libssh2,Pid,谁能解释一下如何从一个用ssh2\u exec启动的进程中检索ProcessID?我尝试了很多方法,但它只给出了以下消息“资源id#6” 下面是我正在努力处理的代码,但是没有回显ProcessID,我只得到了“Resource id#6” 这将帮助您找到进程id <?php //this will return the process id $pid = getmypid(); //you can check the process id if(file_exists('/proc/'
这将帮助您找到进程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.';
}
我认为应该是:
$pid = ssh2_exec($connection, 'cd /home/servers/; nohup ./sc_serv' .$config .' & > /dev/null 2>&1; echo $!');
要获取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);
getmypid()将给出进程id,它唯一输出的是来自Apache2的进程id。不是从我启动的流程开始的。它仍然只给出“Resource id#6”消息,而不是我启动的流程的实际流程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);