在bash subshel​​l中可以调用一个函数作为后台作业吗?

前端之家收集整理的这篇文章主要介绍了在bash subshel​​l中可以调用一个函数作为后台作业吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
假设我有一个bash功能
Yadda() {
  # time-consuming processes that must take place sequentially
  # the result will be appended >> $OUTFILE
  # $OUTFILE is set by the main body of the script
  # No manipulation of variables in the main body
  # Only local-ly defined variables are manipulated
}

我是否允许在子shell中调用函数作为后台工作?例如.:

OUTFILE=~/result
for PARM in $PARAMLIST; do
  ( Yadda $PARM ) &
done
wait
cat $OUTFILE

你怎么看?

您可以在subshel​​l中调用函数作为后台作业.它将像你在你的例子中输入一样工作.

我在你的例子中看到一个问题.如果某些进程同时完成,那么它们将尝试同时写入到OUTFILE,输出可能会混淆.

我建议让每个进程写入自己的文件,然后在所有进程完成后收集文件.

原文链接:https://www.f2er.com/bash/383786.html

猜你在找的Bash相关文章