PHP: get PID of a specific process
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.开发者_JAVA百科com/?d=m7duotr1 2> /share/MD0_DATA/Qdownload/plowshare/outputteeds.txt > /dev/null &
22526
What am I doing wrong?
Thanks,
Cristian.
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
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);
http://nl2.php.net/manual/en/function.getmypid.php
精彩评论