setlock — open an exclusive lock file then chain
setlock
[--non-blocking] [--ignore] {file
} {next-prog
}
setlock is a chain-loading utility that opens the lock file named file
leaving an open file descriptor in the current process
and then chain loads to next-prog
with the execvp(3) function.
next-prog
may contain its own command line options, which setlock will ignore.
How the lockfile works is system dependent. The lock remains active whilst the file descriptor remains open in any process. Closing the file descriptor, by exiting the process or otherwise, is the only portable operation allowed. It is unspecified what access rights the file descriptor has for the lock file, or whether the descriptor is in blocking mode.
Unless the --non-blocking command line option is used, setlock will wait to obtain the lock whilst another process holds it. If that option is used, it will not wait, but instead will fail to acquire the lock.
Unless the --ignore option is used, failure to acquire the lock, because it isn't a valid lock file, because someone else has the lock and non-blocking mode has been used, or for some other reason, will cause setlock to print an error message and exit with a failure status instead of chaining. If that option is used, it will still exit on failure, but without printing an error message and with a success status.