简体   繁体   中英

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.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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM