Consider this:

tmux split-window -d program1
program2 # this program depends on some side effects produced by program1

In this case, program2 will start before program1 is ready. program1 will send signals/output when it has produced side-effects that can be consumed by program2.

My question: How can I write a shell script that will wait until program1 is ready before starting program2?

Observation: program2 does not consume program1 output, so this is not solved by connecting the processes with a pipe.

  • Could you explain exactly how can the state of program1 (ready or not ready yet) be determined? And how exactly program1 sends those signals to program2? This can be useful because what you can do is make a script that looks for those signals, and only start program2 when those signals are detected. In any case if the circumstances permit it, it would be better if program2 itself deals with it. (for example. It goes to sleep until the signals wake it up) – Martín Canaval Jan 29 '13 at 20:50
  • I just found the answer – Thiago de Arruda Jan 29 '13 at 22:10

I found the solution here. In the end, it was not TMUX solution(initially I tought tmux would have some mechanism to syncronize the processes running in its panes)

The answer is using named pipes. Since program1 sends output when it is ready, all I need is something like this:

mkfifo /tmp/pipe
tmux split-window -d "program1 > /tmp/pipe 2>&1"
signal=`cat /tmp/pipe`
program2 # This will only run after program1 has output something

Using a tool like FLOM (Free LOck Manager) should allow you to execute something like:

tmux split-window -d "flom -- program1"
flom -- program2 # this program depends on some side effects produced by program1

if "program1" starts before "program2" the expected behavior will be:

  1. flom will create a logical resource and lock it exclusively for "program1"
  2. flom will enqueue on the same logical resource for "program2" and wait until "program1" termination.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.