Portál AbcLinuxu, 9. května 2025 19:35
Dobrý den, potřeboval bych bashi spustit skript, který provádí n paralelně běžících příkazu. Po dokončení těchto příkazů by měly běžet další příkazy sekvenčně (proto nelze využít příkaz &
).
Řešení dotazu:
Bash script processing commands in parallel
$ sleep 5 & [1] 1234 $ sleep 10 & [2] 1235 $ sleep 15 & [3] 1245 $ wait [1] Done sleep 5 [2]- Done sleep 10 [3]+ Done sleep 15
$ man bash
wait [-n] [n ...]
Wait for each specified child process and return its termination status. Each n may be a process ID or a job speci‐
fication; if a job spec is given, all processes in that job's pipeline are waited for. If n is not given, all cur‐
rently active child processes are waited for, and the return status is zero. If the -n option is supplied, wait
waits for any job to terminate and returns its exit status. If n specifies a non-existent process or job, the return
status is 127. Otherwise, the return status is the exit status of the last process or job waited for.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.