[OpenIndiana-discuss] shell script mutex locking or process signaling

Edward Ned Harvey (openindiana) openindiana at nedharvey.com
Thu May 30 14:15:12 UTC 2013


Here's the problem I'm trying to solve:  SMF service is configured to launch things like VirtualBox during startup / shutdown.  This startup process can take a long time (10, 20 minutes) so if there's a problem of any kind for any reason, you might do things like enable and disable or refresh the service ... but each time the script gets launched, it's not aware of the previous one.  I'm really looking for a good way to allow multiple instances of some shell script to signal each other.  Let the earlier instances die and the later instances take over control.

This problem has two parts.  Atomicity of signaling operations (acquiring / releasing mutex, etc), and inter-process signaling.  (Let the later instance signal the earlier instance that it should die.)  It seems easy enough, as long as you have a good atomic operation for locking, the process that acquired lock can write its PID into a file, and later instances can "kill" that PID.

I'm looking around, and not finding any great answers.  So far, using mkdir, it's easy to see there exists a way to do mutex locking, and you could easily write your PID into the subdir that was just created; unfortunately, the problem is when a script gets killed, leaving the stale lock.  So I'm looking for something better than "mkdir" to use for locking.

I see there are a bunch of C constructs available ... mutex_init, etc.  Surely there must be a wrapper application around this kind of thing, right?

Thanks, everyone, for any suggestions you may offer.


More information about the OpenIndiana-discuss mailing list