相关疑难解决方法(0)

Bash:等待固定数量的进程

我写了一个 bash 脚本,它执行一个 Java jar n次。

在实践中,我定义了 e foo()函数,包含对jar的调用,然后我运行这个脚本:

for RUN in $(seq 1 $RUNS) 
do 
    foo & 
done
Run Code Online (Sandbox Code Playgroud)

现在,我不想在jar中并行执行运行时间。等待限制并行执行的数量(例如每 10 个进程)?wait

bash jobs background-process

6
推荐指数
2
解决办法
2560
查看次数

一次运行命令

我有包含以下命令的文本文件

command1 file1_input; command2 file1_output
command1 file2_input; command2 file2_output
command1 file3_input; command2 file3_output
command1 file4_input; command2 file4_output
command1 file5_input; command2 file5_output
command1 file6_input; command2 file6_output
command1 file7_input; command2 file7_output
................
................
................
................
................
Run Code Online (Sandbox Code Playgroud)

我将此文件命名为“commands”,然后使用“ chmod a+x ” 授予它权限

我希望先运行命令 1,然后再运行命令 2。此外,我希望将其同时应用于所有文件(file1、file2、.... 等)。我怎样才能修改这个文件的内容来做到这一点?

我尝试了以下但没有奏效:

(
command1 file1_input; command2 file1_output
command1 file2_input; command2 file2_output
command1 file3_input; command2 file3_output
command1 file4_input; command2 file4_output
command1 file5_input; command2 file5_output
command1 file6_input; command2 file6_output
command1 file7_input; command2 file7_output
................
................
................
................
................
)&
Run Code Online (Sandbox Code Playgroud)

scripting shell-script parallelism

5
推荐指数
2
解决办法
109
查看次数

如何控制for循环?

假设我们有“for循环”如下:

#!/bin/bash
for i in $(cat test_file); do 
echo $i
done
Run Code Online (Sandbox Code Playgroud)

文本文件的内容是父文件夹中的文件夹名称

如果 text_file 包含 10000 个条目(即变量 i),我如何告诉“for 循环”在每 10 个“回声”之间休眠 10 秒。换句话说,当 for 循环读取 text_file 中的变量 i 时,如何控制 for 循环可以在每个特定时间段运行的变量数量?所以输出如下:

   Variable #1
   Variable #2
   Variable #3
   .
   .
   .
   .
   sleep 10
    Variable #11
    Variable #12
    Variable #13
   .
   .       .
Run Code Online (Sandbox Code Playgroud)

bash

2
推荐指数
1
解决办法
370
查看次数