Question

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.

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top