【问题标题】:Place process in background with find+xargs+nohup [duplicate]使用 find+xargs+nohup 将进程置于后台 [重复]
【发布时间】:2021-09-29 19:05:04
【问题描述】:

在哪里添加 nohup& 以将其放在后台? 我尝试了多个地方,但都没有运气。

find . -links 2  -type d |
xargs -I{} -P 5 -n 1  bash -c 'cd "{}" && run_script.sh'

【问题讨论】:

  • bash -c 'cd "{}"... 将在 " 上中断,使用参数 - xargs -n1 bash -c 'cd "$1"' --

标签: bash xargs nohup


【解决方案1】:

最简单的答案 - 把它放在行尾。

find . -links 2 -type d | xargs -I{} -P 5 -n 1 bash -c 'cd "{}" && run_script.sh' &

这有效地将管道置于后台。
不过,您可能会想要管理您的 i/o。

【讨论】:

  • -P 5-n 应该是-P 5 -n。你可以把nohup放在find前面。
  • 是的,我必须在我的测试中修复它,却忘了在这里修复它。谢谢。
  • run_script.sh 是长时间运行的进程。即使 find 在后台,它也会终止
  • 也许你需要的是每个目录中的cd "{}" && nohup run_script.sh &'. That will thow a nohup.out`,但你的输出(如果有的话)将清楚地与相关位置相关联。如果需要,您可以管理自己的重定向。确保这里有有用的日志记录,即使它只是在run_script.sh 中使用set -x 打开调试模式。
猜你喜欢
  • 1970-01-01
  • 2011-07-14
  • 2012-02-05
  • 2011-02-21
  • 2020-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多