*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->Linux man pages -> flock (2)              



NAME    [Toc]    [Back]

       flock - apply or remove an advisory lock on an open file

SYNOPSIS    [Toc]    [Back]

       #include <sys/file.h>

       int flock(int fd, int operation)

DESCRIPTION    [Toc]    [Back]

       Apply  or  remove an advisory lock on an open file.  The file is specified
 by fd.  Valid operations are given below:

	      LOCK_SH	Shared lock.  More than one process may hold a	shared
			lock for a given file at a given time.

	      LOCK_EX	Exclusive  lock.   Only one process may hold an exclusive
 lock for a given file at a given time.

	      LOCK_UN	Unlock.

	      LOCK_NB	Don't  block  when  locking.   May  be	specified  (by
			or'ing) along with one of the other operations.

       A  single  file	may  not simultaneously have both shared and exclusive

       A file is locked (i.e., the  inode),  not  the  file  descriptor.   So,
       dup(2) and fork(2) do not create multiple instances of a lock.

RETURN VALUE    [Toc]    [Back]

       On  success,  zero is returned.	On error, -1 is returned, and errno is
       set appropriately.

ERRORS    [Toc]    [Back]

	      The file is locked and the LOCK_NB flag was selected.

CONFORMING TO    [Toc]    [Back]

       4.4BSD (the flock(2) call first appeared in 4.2BSD).

NOTES    [Toc]    [Back]

       flock(2) does not lock files over NFS.  Use fcntl(2) instead: that does
       work  over  NFS,  given	a  sufficiently  recent version of Linux and a
       server which supports locking.

       flock(2) and fcntl(2) locks have different semantics  with  respect  to
       forked processes and dup(2).

SEE ALSO    [Toc]    [Back]

       open(2), close(2), dup(2), execve(2), fcntl(2), fork(2), lockf(3)

       There are also locks.txt and mandatory.txt in /usr/src/linux/Documenta-

Linux				  1998-12-11			      FLOCK(2)
[ Back ]
 Similar pages
Name OS Title
lockf Linux apply, test or remove a POSIX lock on an open file
lockf Tru64 Lock and unlocks regions of open file descriptors
patch Linux apply a diff file to an original
patch IRIX apply a diff file to an original
patch FreeBSD apply a diff file to an original
patch OpenBSD apply a diff file to an original
VOP_ADVLOCK FreeBSD advisory record locking
noderun IRIX Run process on specific node (advisory specification)
AFidentifyfd IRIX retrieve the audio file format of a file descriptor / open AFfilehandle
IvToRib IRIX convert an Open Inventor 2.0 file to a Renderman .rib file
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service