Command Line Semaphore Utility

I want to write a command line utility that can be used to synchronize program execution across different consoles.

Console A: 
$ first_program && semaphore -signal

Console B:
$ semaphore -wait && second_program

      

The first program is time consuming. The second program can only start after the first program has finished.

What synchronization object do I need to implement?

+2


a source to share


2 answers


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

First create a channel 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. Reading will be blocked until written, and vice versa.

+5


a source


If they are on the same computer, the first program might touch the temporary file.



There is a Gamin module in python that will allow your second program to sit and wait without tying up resources. It's not busy waiting or doing anything with sleep or anything like that.

0


a source







All Articles