setlock(1)

NAME
setlock - run a program with a file locked

SYNTAX
setlock [ -nNxX ] file program [ arg ... ]

DESCRIPTION
setlock opens file for writing (creating it if it does not exist), obtains an exclusive lock on it, and runs program. Normally the lock disappears when program exits. (Here's the complete story: program is given a descriptor for a locked ofile pointing to file. The lock disappears when this ofile is (1) closed by all the processes that have descriptors for it or (2) explicitly unlocked.)

OPTIONS

-n  No delay. If file is locked by another process, setlock gives up.

-N  (Default.) Delay. If file is locked by another process, setlock waits until it can obtain a new lock.

-x  If file cannot be opened (or created) or locked, setlock exits zero.

-X  (Default.) If file cannot be opened (or created) or locked, setlock prints an error message and exits nonzero.

SEE ALSO
flock(2), lockf(3)