views:

70

answers:

3

I want to write a command line utility that can be used to synchronize the execution off programs in different consoles.

Console A: 
$ first_program && semaphore -signal

Console B:
$ semaphore -wait && second_program

The first program takes a long take to complete. The second program can only start when the first program has finished.

Which synchronization object do I need to implement this?

A: 

If they're on the same machine the first program can touch a temporary file.

There is a Gamin module in python that will allow your second program to sit there and wait while not tying up resources. It isn't a busy wait, or doing anything with sleep or stuff like that.

eric.frederich
A: 

Perhaps this is useful:

Recipe 498191: Waitable, cross-process threading.Event class. (Python)

compie
+5  A: 

You don't need to use Python for this. Considering you are using Unix, try this:

First, create a pipe for the semaphore.

mknod /tmp/semaphore p

Then, the programs:

Console A:
$ first_program && echo a > /tmp/semaphore

Console B:
$ read < /tmp/semaphore && second_program

Actually, this method works both ways. The read will block until there is a write, and vice versa.

petersohn
Was just about to write exact same thing using `mkfifo` :)
Nikolai N Fetissov