lockexec - lockfile management and control.
lockexec [--share] [--nowait] file.lock cmd [arg]...
The normal lock file mechanism available at the shell level in unix is the 'lockfile' command. It works by checking existence of a series of files to control locking operations. There are instances where this simple scheme fails :
Allowing shared or exclusive access to the lockfile. For example having multiple 'reader' processes, but only one 'writer' process.
If the process owning the lockfile unexpectedly terminates and does not delete the lockfile then it is difficult to determine the correct course of action.
lockexec was built to resolve these issues. It is allows the creation of both shared and exclusive locks. And since it depends on the fcntl state of of file, and not the files existance, if can't be thrown by tasks that terminate without removing the lockfiles.
A large sql query is broken into three parallel selects, each into different temporary tables, followed by a join on the three temporary tables.
lockexec -share sql.lock sql 'select into temp1 ....' & lockexec -share sql.lock sql 'select into temp2 ....' & lockexec -share sql.lock sql 'select into temp3 ....' & lockexec sql.lock sql 'select into target ...'
lockfile, fcntl
Possibly NFS safe. Only ever been tested and compiled on Linux.