How do you run multiple programs in parallel from a bash script?

前端 未结 15 1396
眼角桃花
眼角桃花 2020-11-22 06:31

I am trying to write a .sh file that runs many programs simultaneously

I tried this

prog1 
prog2

15条回答
  •  轮回少年
    2020-11-22 07:07

    You can use wait:

    some_command &
    P1=$!
    other_command &
    P2=$!
    wait $P1 $P2
    

    It assigns the background program PIDs to variables ($! is the last launched process' PID), then the wait command waits for them. It is nice because if you kill the script, it kills the processes too!

提交回复
热议问题