加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 01:31:14 所属栏目:安全 来源:网络整理
导读:假设我有一个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 loca
假设我有一个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,输出可能会混淆.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读