1

To automate simulations I created a single bash script (see below) running 3 python programs in parallel, interconnected with sockets, each in a new terminal (The behavior of the software requires the 3 subprograms to be ran in separate terminals).

#!/bin/bash
    
gnome-terminal -- ./orchestrator.py -c config/orchestrator/configWorstCaseRandomV.yml -v
gnome-terminal -- ./server.py -c config/server/config.yml -s config/server/systems/ault14mix.yml --simulate -v
gnome-terminal -- ./simulation/traces/simulate_traces.py -m September

What I want to do is to re-execute the same 3 pythons programs but with different parameters ONLY after the 3 previous programs have ended. But here the 3 programs are started at the same time and I have no way of knowing when then end in my bash script.

I tried to simply add the corresponding commands at the end of my script, but logically it doesn't wait for the previous simulation to be completed to start the next 3 programs.

So my question is, is there a way of knowing when a program is ended in another terminal before executing the next lines of a bash script ?

7
  • 2
    Is there a reason why you run the python scripts using gnome-terminal? Commented Jun 21, 2021 at 14:56
  • Use a semicolon after each bash command, to make them run one after another. Commented Jun 21, 2021 at 14:58
  • iiuc, the op wants to run the 3 programs in parallel. but once all have finished, he wants to start anew. Commented Jun 21, 2021 at 14:59
  • I suspect the first two can be simply run in the background (e.g., ./orchestrator.py ... &). The third can just be run in your current terminal, and after it exits, you can kill the orchestrator and server and start again. Commented Jun 21, 2021 at 15:11
  • @vdavid This runs the python scripts in a dedicated terminal as otherwise they would be blocking each others execution. Commented Jun 21, 2021 at 15:17

1 Answer 1

1

I assume gnome-terminal is used only to run programs in parallel, and without it, each Python script would run in the foreground.

In this case you may run them in background using the ampersand character & (instead of gnome-terminal) and get their process ID with $! and finally wait for them with the wait command, e.g.:

#!/bin/bash
    
./orchestrator.py -c config/orchestrator/configWorstCaseRandomV.yml -v &
pid1=$!
./server.py -c config/server/config.yml -s config/server/systems/ault14mix.yml --simulate -v &
pid2=$!
./simulation/traces/simulate_traces.py -m September &
pid3=$!
wait $pid1 $pid2 $pid3
Sign up to request clarification or add additional context in comments.

1 Comment

Seems like exactly what I was looking for ! I'll try tomorrow morning and come back to you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.