exec() not returning process ID

时间秒杀一切 提交于 2020-01-05 07:36:42

问题


I'm using the PHP exec() function to execute the Canu assembler programs, and I want to get its process ID within the same script.

The problem is exec() not returning any PID, even the process is running successfully.

The processes are started like this:

$gnuplot_path = '/usr/bin/gnuplot';

$command = 'nohup canu -d . -p E.coli gnuplot='.$gnuplot_path.' genomeSize=4.8m useGrid=false maxThreads=30 -pacbio-raw /path/to/p6.25x.fastq > /path/to/process.err 2>&1 &';

Currently, I try to determine if the process is still running by:

$pid = exec($command, $output);
var_dump($pid);

and also this:

exec($command, $pid, $return_var);
print_r($pid);
echo "$return_var\n";

However, I got output of string(0) "" and Array ( ) 0 respectively.

Please let me know how to solve this. Thanks much.


回答1:


This one is tricky. What I would do:

$gnuplot_path = '/usr/bin/gnuplot';
$command = 'nohup canu -d . -p E.coli gnuplot='.$gnuplot_path.' genomeSize=4.8m useGrid=false maxThreads=30 -pacbio-raw /path/to/p6.25x.fastq > /path/to/process.err 2>&1';
$command .= ' & echo $!';

$pid = exec($command, $output, $a);
var_dump($output[0]);


来源:https://stackoverflow.com/questions/43012298/exec-not-returning-process-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!