我有这样的剧本,如果我运行它,我从所列出使用top命令的一个在数据库中输入一个不同的PID号:PHP后台进程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(随机数,现在choosen只是提出一个观点)
与顶级commnand上市PID号:11161.
列出了top命令的PID号总是由2
更大然后从数据库中之一,它让我发疯...
感谢,
克里斯蒂安。
“11159”的顶部(或'ps aux')是什么?有没有机会是'nohup'? – ircmaxell 2010-11-05 16:38:58
再次运行函数,我得到了这个结果:7696 httpdusr 1856 S/opt/bin/bash/opt/bin/plowdown使用top,在数据库中输入了7694 ... ??? – Chris19 2010-11-05 16:57:24
但是什么是'7694'?我的猜测是你得到的PID返回的是'nohup'的pid。但是'nohup'作为一个新的进程跨越了自己的tty,所以pid应该和'nohup'不同# – ircmaxell 2010-11-05 17:01:10