Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
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

2 Answers 2

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
share|improve this answer

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.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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