setlock

## Name

setlock — runs another program with a file locked.

## Synopsis

`setlock` [-n] [-N] [-x] [-X] {`fn`} {`child`}

## Description

`fn` is a single argument. `child` consists of one or more arguments.

setlock opens ``fn`` for writing (creating it if it does not exist), obtains an exclusive lock on it, and runs `child`.

Normally the lock disappears when `child` exits.

Here's the complete story: `child` is given a descriptor for a locked ofile pointing to the disk file named ``fn``. The lock disappears when this ofile is

- either closed by all the processes that have descriptors for it

- or explicitly unlocked.

## Options

[-n]

  No delay. If ``fn`` is locked by another process, setlock gives up.

[-N]

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

[-x]

  If ``fn`` cannot be opened (or created) or locked, setlock exits zero.

[-X]

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

## See also

supervise(1)
svc(1)
svok(1)
svstat(1)
svscanboot(1)
svscan(1)
readproctitle(1)
fghack(1)
pgrphack(1)
multilog(1)
tai64n(1)
tai64nlocal(1)
setuidgid(1)
envuidgid(1)
envdir(1)
softlimit(1)

## Author

Original code and documentation by Daniel J. Bernstein. Converted to manual pages and updated by Gerrit Pape in 2000, 2001, and 2002. Converted to DocBook XML by Jonathan de Boyne Pollard.