PHP:获取特定进程的PID [英] PHP: get PID of a specific process

查看:77
本文介绍了PHP:获取特定进程的PID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a QNAP box, that runs a flavor of linux and I am having problems getting the PID of a process using a php script. What I have so far:

$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运行命令,则会得到:

If I run the command through PUTTY, I get:

[~] # 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

我在做什么错了?

谢谢

克里斯蒂安.

推荐答案

除非通常是交互式的,否则shell通常不会在后台启动该进程的PID.否则,您将在启动过程中仅从开始的所有进程的PID中获得大量输出.

The shell does not normally print the PID of a process it starts in background, unless it's interactive. Otherwise, you would get tons of output during bootup just from the PIDs of all the processes that get started.

因此,您需要使外壳程序打印PID.做

So you need to make the shell print the PID. Do

 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);

这篇关于PHP:获取特定进程的PID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆