flock
lock files for use by shell scripts
- Contributed by
- David J. Fiander
- Obtained from
- I wrote it
- Restrictions
- SCO owns it (because I wrote it. Ask John MacMillan)
- Description
-
This locks files using fcntl file locking. If the lock
is successfully acquired, then the pid of a process holding
the lock is printed on stdout, otherwise and error message
is printed, and the exit status is the value of errno.
"flock -r" gives a read or shared lock, "flock -w", or just
"flock", gives a write, or exclusive, lock.
- Productivity
- great for locking mailboxes while you edit them with vi ;->
- Safety
- Wrote it. It's only 2 screens long.
- Work Planned
- None
- Documentation
- None
- Verification
- say "flock ", see a pid. try again. It
should fail. Kill the given pid, and try the lock again.
NOTE: If compiled on XENIX, write locks are pretty useless,
since the only locking implemented is mandatory.
Note that all this source is configured to be installed under
/usr/skunk.
To build it for a different location, compile with
make CTRBDESTDIR=directory.