exec() 不返回进程 ID

exec() not returning process ID

我正在使用 PHP exec() 函数来执行 Canu assembler 程序,我想在同一个脚本中获取它的进程 ID。

问题是 exec() 没有返回任何 PID,即使进程 运行 成功。

进程是这样​​启动的:

$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 &';

目前,我尝试通过以下方式确定进程是否仍然 运行:

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

还有这个:

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

但是,我分别得到了 string(0) ""Array ( ) 0 的输出。

请告诉我如何解决这个问题。非常感谢。

这个很棘手。我会做什么:

$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]);