我有這樣的劇本,如果我運行它,我從所列出使用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