NAME

lock - obtain a lock before running a command


SYNOPSIS

lock [-p pidfile] [-1] [-a] [-s] key command [files...]

lock -q key


DESCRIPTION

Lock obtains a named lock (specified by key), runs a specified command and then releases the lock. The locking is NFS-safe, being based on making an empty subdirectory in an area shared by the processes using the lock.


OPTIONS

-p pidfile

Record the process-id of the command in the file named pidfile.

-1

Onceonly. Instead of waiting for the lock to become free, immediately exit successfully without running command if the lock is taken. Useful to ensure some daemon is active without accidentally running two instances.

-a

Asynchronous. If the lock is obtained, run command as an asynchronous child.

-q

Query the lock named key, returning a meaningful exit status (0 for lock taken, 1 for lock not taken). Useful in if statements.

-s

Silent. Do not report ``waiting for lock...'' after the initial boredom period.

key

Then name of the lock to obtain. An empty key silently bypasses any locking and just runs command.


EXIT STATUS

Non-zero if the lock cannot be obtained, or if the command returns a non-zero exit status.


SEE ALSO

cs::Lock(3)


AUTHOR

Cameron Simpson <cs@zip.com.au> 01oct1997; converted to perl to beat shell fork/exec load during high contention 10feb1999.