parallel_batch.sh

Shellマスター

Explorer

C40
C++40
C#40
Dart40
Go40
Java40
JavaScript40
Kotlin40
Objective-C40
Perl40
PHP40
Python40
R40
Ruby40
Rust40
Shell
初級10
中級10
上級10
エキスパート5
マスター5
parallel_batch.sh
trap_cleanup.sh
json_parser.sh
config_loader.sh
retry_wrapper.sh
Swift40
TypeScript40
parallel_batch.sh
Click to focus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
process_batch() {
   local -r batch_size="${1:-10}"
   local -r max_jobs="${2:-4}"
   while IFS= read -r item; do
       while (( $(jobs -r | wc -l) >= max_jobs )); do
           sleep 0.1
       done
       {
           echo "Processing: $item"
           curl -s "API/$item" | jq '.data' > "output/${item}.json"
       } &
   done
   wait
}
find . -name "*.log" | process_batch 10 4
0WPM0%0:000/396(0%)|Ln 1, Col 1
UTF-8Shell

関連する練習問題