【问题标题】:exec() not returning process IDexec() 不返回进程 ID
【发布时间】:2017-08-18 03:32:08
【问题描述】:

我正在使用 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 的输出。

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

【问题讨论】:

  • 使用ps aux | grep "process name",然后解析pid的输出,exec() 没有其他php shell相关函数返回一个pid,只有在它成功与否的情况下,也许输出。

标签: php exec bioinformatics pid dna-sequence


【解决方案1】:

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

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

【讨论】:

  • 你能解释一下你在这里做了什么吗?我正在后台执行一个脚本并得到与 OP 使用 exec($command,$output); 相同的空字符串 "" 我有吗在命令或其他内容中使用任何特定标志。
猜你喜欢
  • 2012-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 2012-10-14
相关资源
最近更新 更多