PHP:获取特定进程的PID
我有一个 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
我做错了什么?
谢谢,
克里斯蒂安。
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;
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
What am I doing wrong?
Thanks,
Cristian.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
shell 通常不会打印它在后台启动的进程的 PID,除非它是交互式的。否则,在启动期间您将仅从所有启动进程的 PID 中获得大量输出。
所以你需要让shell打印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.
So you need to make the shell print the PID. Do
http://nl2.php.net/manual/en/function.getmypid.php
http://nl2.php.net/manual/en/function.getmypid.php