# phpman > info > setlock

[setlock(8)](https://www.chedong.com/phpMan.php/man/setlock/8/markdown)                  System Manager's Manual                 [setlock(8)](https://www.chedong.com/phpMan.php/man/setlock/8/markdown)

NAME
       setlock - runs another program with a file locked.

SYNOPSIS
       setlock [ -nNxX ] 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), ob-
       tains 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

       o      closed by all the processes that have descriptors for it or

       o      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,  set-
              lock prints an error message and exits nonzero.

SEE ALSO
       [supervise(8)](https://www.chedong.com/phpMan.php/man/supervise/8/markdown),  [svc(8)](https://www.chedong.com/phpMan.php/man/svc/8/markdown),  [svok(8)](https://www.chedong.com/phpMan.php/man/svok/8/markdown),  [svstat(8)](https://www.chedong.com/phpMan.php/man/svstat/8/markdown),  [svscanboot(8)](https://www.chedong.com/phpMan.php/man/svscanboot/8/markdown), [svscan(8)](https://www.chedong.com/phpMan.php/man/svscan/8/markdown),
       [readproctitle(8)](https://www.chedong.com/phpMan.php/man/readproctitle/8/markdown),  [fghack(8)](https://www.chedong.com/phpMan.php/man/fghack/8/markdown),  [pgrphack(8)](https://www.chedong.com/phpMan.php/man/pgrphack/8/markdown),   [multilog(8)](https://www.chedong.com/phpMan.php/man/multilog/8/markdown),   [tai64n(8)](https://www.chedong.com/phpMan.php/man/tai64n/8/markdown),
       [tai64nlocal(8)](https://www.chedong.com/phpMan.php/man/tai64nlocal/8/markdown), [setuidgid(8)](https://www.chedong.com/phpMan.php/man/setuidgid/8/markdown), [envuidgid(8)](https://www.chedong.com/phpMan.php/man/envuidgid/8/markdown), [envdir(8)](https://www.chedong.com/phpMan.php/man/envdir/8/markdown), [softlimit(8)](https://www.chedong.com/phpMan.php/man/softlimit/8/markdown)

       <http://cr.yp.to/daemontools.html>

                                                                    [setlock(8)](https://www.chedong.com/phpMan.php/man/setlock/8/markdown)
