PHP:获取特定进程的PID

时间:2010-11-01 07:40:54

标签: php linux nohup

我有一个QNAP框,运行linux的味道,我在使用php脚本获取进程的PID时遇到问题。到目前为止我所拥有的:

$command = "PATH=$PATH:/share/MD0_DATA/.qpkg/Optware/bin: nohup /opt/bin/plowdown -o /share/MD0_DATA/Qdownload/plowshare http://www.megaupload.com/?d=m7duotr1 2> /share/MD0_DATA/Qdownload/plowshare/outputeeds.txt > /dev/null &";
exec($command, $out);
$result = $out[0];
echo $result;

如果我通过PUTTY运行命令,我会得到:

[~] # nohup /opt/bin/plowdown -o /share/MD0_DATA/Qdownload/plowshare http://www.megaupload.com/?d=m7duotr1 2> /share/MD0_DATA/Qdownload/plowshare/outputteeds.txt > /dev/null &
22526

我做错了什么?

谢谢,

的Cristian。

2 个答案:

答案 0 :(得分:2)

shell通常不会打印它在后台启动的进程的PID,除非它是交互式的。否则,您只需从启动的所有进程的PID中获取大量输出。

所以你需要让shell打印PID。做

 exec("(PATH=$PATH:/share/MD0_DATA/.qpkg/Optware/bin: " . 
      "nohup /opt/bin/plowdown -o /share/MD0_DATA/Qdownload/plowshare " .
      "http://www.megaupload.com/?d=m7duotr1 2> " . 
      "/share/MD0_DATA/Qdownload/plowshare/outputeeds.txt > /dev/null &);" . 
      "echo $$;", $out);

答案 1 :(得分:1)