【发布时间】:2010-11-05 16:32:58
【问题描述】:
我有这个脚本,如果我运行它,我会在数据库中输入一个与顶部命令列出的不同的 PID 号:
<?php
error_reporting(0);
include_once "config/mysql.php";
// the path
$path = "PATH=$PATH:/share/MD0_DATA/.qpkg/Optware/bin:";
//random number for the log file name
$random = rand(1,500000);
//initial download location
$init_loc="/share/MD0_DATA/Qdownload/plowshare";
$items = rtrim($_POST['items'],",");
$sql = mysql_query("SELECT url, pid FROM plow WHERE id IN ($items)") or die ('Error: ' . mysql_error());
while ($db_row = mysql_fetch_assoc($sql)) {
//random number for the log file name
$random = rand(1,500000);
//log file name
$out_file = '/share/MD0_DATA/Qdownload/plowshare/Logs/log'.$random.'.txt';
//command 1
$command = exec("($path" . " nohup /opt/bin/plowdown -o '$init_loc' " . "'".$db_row['url']."' 2> " . "'$out_file' > /dev/null &);" . "echo $$;", $out);
exec($command, $out);
$query = mysql_query("UPDATE plow SET state = 'Active', pid = '$out[0]' WHERE id IN ($items)") or die ('Error: ' . mysql_error());
}
mysql_close();
?>
结果总是一样的:
在数据库中输入的PID号:11159(随机数,现在选择只是为了说明一点)
顶部命令列出的PID号:11161。
顶部命令列出的 PID 号总是比数据库中的 PID 号大 2。
它让我发疯......
谢谢,
克里斯蒂安。
【问题讨论】:
-
top(或ps aux)中的11159是什么?有没有可能是nohup? -
再次运行函数,我得到了这个结果: 7696 httpdusr 1856 S /opt/bin/bash /opt/bin/plowdown using top,在数据库中输入了 7694 ... ???
-
但是
7694是什么?我的猜测是您返回的 PID 是nohup的 pid。但是nohup在它自己的 tty 上将命令作为一个新进程跨越,所以 pid 应该不同于nohup的... -
@ircmaxell 如果您可以访问 Linux 机器,请尝试运行此命令 nohup "some command" 2> output.txt > /dev/null & ,最后看到的数字应该是nohup 的 PID 号并使用 top 命令检查该命令的 PID 号。谢谢。