【发布时间】:2018-11-09 20:24:44
【问题描述】:
所以我有这个函数,我希望这个函数同时运行它本身包含的所有内容。到目前为止,它不起作用,并且根据其他消息来源,这就是您的操作方式。如果函数不是并行的,函数本身就可以工作。
#!/bin/bash
foo () {
cd ${HOME}/sh/path/to/script/execute
for f in *.sh; do #goes to "execute" directory and executes all
#scripts the current directory "execute" basically run-parts without cron
cd ~/sh/path/to/script
while IFS= read -r l1 #Line 1 in master.txt
IFS= read -r l2 #Line 2 in master.txt
IFS= read -r l3 #Line 3 in master.txt
do
cd /dev/shm/arb
echo ${l1} > arg.txt & echo ${l2} > arg2.txt & echo ${l3} > arg3.txt
cd ${HOME}/sh/path/to/script/execute
bash -H ${f} #executes all scripts inside "execute" folder
cd ~/sh/path/to/script/here
./here.sh &
cd ~/sh/path/to/script &
done <master.txt
done
}
export -f foo
parallel ::: foo
结果
#No result at all....., just buffers. htop doesn't acknowledge any
#processes, and when this runs its pretty taxing on the cores.
master.txt 内容
如果这是相关的:
apple_fruit
apple_veggie
veggie_fruit
#apple changes
pear_fruit
pear_veggie
veggie_fruit
#pear changes
cucumber_fruit
...
我对使用并行非常陌生,不知道它在高级(和基本)情况下是如何工作的,所以循环会干扰吗?如果它确实干扰,是否有解决方法?
【问题讨论】:
-
GNU Parallel 的理念是你有很多事情要做,你可以并行执行很多
foo()的实例。所以,你需要瞄准parallel foo ::: <lots of things> -
你认为
cd somewhere &是做什么的?它在后台启动一个新进程,然后更改目录并退出......而不影响前台进程。 -
这是一个错字,我删除了它
-
你不能同时将数十或数百个并行任务全部写入
arg[1-3].txt- 你会弄得一团糟! -
唯一应该进去的就是
master.txt的前三行,它会重写,因为它没有被附加。
标签: bash loops parallel-processing sh gnu-parallel