庆典:开始在后台的多个链接命令 [英] bash: start multiple chained commands in background
问题描述
我想在paralel运行某些命令,在后台,使用bash。这里就是我想要做的:
I'm trying to run some commands in paralel, in background, using bash. Here's what I'm trying to do:
forloop {
//this part is actually written in perl
//call command sequence
print `touch .file1.lock; cp bigfile1 /destination; rm .file1.lock;`;
}
反引号(``)之间的部分产生一个新的外壳,相继执行的命令。问题是,已执行的最后一个命令后,才控制到原来的程序返回。我想执行的背景下,整个声明(我不期待任何输出/返回值),我想在循环继续运行。
The part between backticks (``) spawns a new shell and executes the commands in succession. The thing is, control to the original program returns only after the last command has been executed. I would like to execute the whole statement in background (I'm not expecting any output/return values) and I would like the loop to continue running.
调用程序(即具有循环中的一个)不会结束,直到所有的衍生弹完成。
The calling program (the one that has the loop) would not end until all the spawned shells finish.
我可以使用线程在Perl产卵不同的线程调用其中不同的炮弹,但似乎矫枉过正...
I could use threads in perl to spawn different threads which call different shells, but it seems an overkill...
我可以启动一个shell,给它一组命令,告诉它去后台?
Can I start a shell, give it a set of commands and tell it to go to the background?
推荐答案
我没有关于
print `(touch .file1.lock; cp bigfile1 /destination; rm .file1.lock;) &`;
括号意味着执行在子shell,但不应该伤害。
The parentheses mean execute in a subshell but that shouldn't hurt.
这篇关于庆典:开始在后台的多个链接命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!