]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/fcntl.2
user_namespaces.7: Minor rewordings of recently added text
[thirdparty/man-pages.git] / man2 / fcntl.2
CommitLineData
fea681da 1'\" t
fea681da 2.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
99b5ab79
MK
3.\" and Copyright (C) 1993 Michael Haardt, Ian Jackson;
4.\" and Copyright (C) 1998 Jamie Lokier;
5.\" and Copyright (C) 2002-2010, 2014 Michael Kerrisk;
6.\" and Copyright (C) 2014 Jeff Layton
6bdad35b 7.\" and Copyright (C) 2014 David Herrmann
580082a1 8.\" and Copyright (C) 2017 Jens Axboe
fea681da 9.\"
93015253 10.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
11.\" Permission is granted to make and distribute verbatim copies of this
12.\" manual provided the copyright notice and this permission notice are
13.\" preserved on all copies.
14.\"
15.\" Permission is granted to copy and distribute modified versions of this
16.\" manual under the conditions for verbatim copying, provided that the
17.\" entire resulting derived work is distributed under the terms of a
18.\" permission notice identical to this one.
c13182ef 19.\"
fea681da
MK
20.\" Since the Linux kernel and libraries are constantly changing, this
21.\" manual page may be incorrect or out-of-date. The author(s) assume no
22.\" responsibility for errors or omissions, or for damages resulting from
23.\" the use of the information contained herein. The author(s) may not
24.\" have taken the same level of care in the production of this manual,
25.\" which is licensed free of charge, as they might when working
26.\" professionally.
c13182ef 27.\"
fea681da
MK
28.\" Formatted or processed versions of this manual, if unaccompanied by
29.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 30.\" %%%LICENSE_END
fea681da
MK
31.\"
32.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
33.\" Modified 1995-09-26 by Andries Brouwer <aeb@cwi.nl>
34.\" and again on 960413 and 980804 and 981223.
35.\" Modified 1998-12-11 by Jamie Lokier <jamie@imbolc.ucc.ie>
36.\" Applied correction by Christian Ehrhardt - aeb, 990712
c11b1abf 37.\" Modified 2002-04-23 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
38.\" Added note on F_SETFL and O_DIRECT
39.\" Complete rewrite + expansion of material on file locking
40.\" Incorporated description of F_NOTIFY, drawing on
41.\" Stephen Rothwell's notes in Documentation/dnotify.txt.
42.\" Added description of F_SETLEASE and F_GETLEASE
43.\" Corrected and polished, aeb, 020527.
c11b1abf 44.\" Modified 2004-03-03 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
45.\" Modified description of file leases: fixed some errors of detail
46.\" Replaced the term "lease contestant" by "lease breaker"
c11b1abf 47.\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 48.\" Added notes on capability requirements
1c1e15ed 49.\" Modified 2004-12-08, added O_NOATIME after note from Martin Pool
c13182ef 50.\" 2004-12-10, mtk, noted F_GETOWN bug after suggestion from aeb.
2f36a807 51.\" 2005-04-08 Jamie Lokier <jamie@shareable.org>, mtk
d9bfdb9c 52.\" Described behavior of F_SETOWN/F_SETSIG in
71fea607 53.\" multithreaded processes, and generally cleaned
2f36a807 54.\" up the discussion of F_SETOWN.
c13182ef 55.\" 2005-05-20, Johannes Nicolai <johannes.nicolai@hpi.uni-potsdam.de>,
9d2a7b1f
MK
56.\" mtk: Noted F_SETOWN bug for socket file descriptor in Linux 2.4
57.\" and earlier. Added text on permissions required to send signal.
dd164bfc
MK
58.\" 2009-09-30, Michael Kerrisk
59.\" Note obsolete F_SETOWN behavior with threads.
60.\" Document F_SETOWN_EX and F_GETOWN_EX
14f7d1a4
MK
61.\" 2010-06-17, Michael Kerrisk
62.\" Document F_SETPIPE_SZ and F_GETPIPE_SZ.
a25d701d 63.\" 2014-07-08, David Herrmann <dh.herrmann@gmail.com>
6bdad35b 64.\" Document F_ADD_SEALS and F_GET_SEALS
580082a1
JA
65.\" 2017-06-26, Jens Axboe <axboe@kernel.dk>
66.\" Document F_{GET,SET}_RW_HINT and F_{GET,SET}_FILE_RW_HINT
fea681da 67.\"
9ba01802 68.TH FCNTL 2 2019-03-06 "Linux" "Linux Programmer's Manual"
fea681da
MK
69.SH NAME
70fcntl \- manipulate file descriptor
71.SH SYNOPSIS
72.nf
73.B #include <unistd.h>
74.B #include <fcntl.h>
778ac627 75.PP
68e0696a 76.BI "int fcntl(int " fd ", int " cmd ", ... /* " arg " */ );"
fea681da
MK
77.fi
78.SH DESCRIPTION
cff88e99
MK
79.BR fcntl ()
80performs one of the operations described below on the open file descriptor
fea681da 81.IR fd .
cff88e99 82The operation is determined by
fea681da 83.IR cmd .
778ac627 84.PP
68e0696a
MK
85.BR fcntl ()
86can take an optional third argument.
87Whether or not this argument is required is determined by
88.IR cmd .
63a6efda 89The required argument type is indicated in parentheses after each
68e0696a
MK
90.I cmd
91name (in most cases, the required type is
ed9821bb 92.IR int ,
68e0696a
MK
93and we identify the argument using the name
94.IR arg ),
95or
96.I void
97is specified if the argument is not required.
778ac627 98.PP
6024e733
MK
99Certain of the operations below are supported only since a particular
100Linux kernel version.
101The preferred method of checking whether the host kernel supports
102a particular operation is to invoke
103.BR fcntl ()
104with the desired
105.IR cmd
106value and then test whether the call failed with
107.BR EINVAL ,
108indicating that the kernel does not recognize this value.
73d8cece 109.SS Duplicating a file descriptor
fea681da 110.TP
ed9821bb 111.BR F_DUPFD " (\fIint\fP)"
6a459f6f
MK
112Duplicate the file descriptor
113.IR fd
114using the lowest-numbered available file descriptor greater than or equal to
115.IR arg .
cff88e99 116This is different from
68e0696a 117.BR dup2 (2),
d9cb0d7d 118which uses exactly the file descriptor specified.
ca92ce95 119.IP
d9cb0d7d 120On success, the new file descriptor is returned.
ca92ce95 121.IP
cff88e99
MK
122See
123.BR dup (2)
124for further details.
ef203e45 125.TP
ed9821bb 126.BR F_DUPFD_CLOEXEC " (\fIint\fP; since Linux 2.6.24)"
635d3959 127As for
ef203e45
MK
128.BR F_DUPFD ,
129but additionally set the
d9cb0d7d 130close-on-exec flag for the duplicate file descriptor.
ef203e45 131Specifying this flag permits a program to avoid an additional
0e92e8cc 132.BR fcntl ()
ef203e45
MK
133.B F_SETFD
134operation to set the
135.B FD_CLOEXEC
136flag.
137For an explanation of why this flag is useful,
e4b4caa6 138see the description of
ef203e45
MK
139.B O_CLOEXEC
140in
141.BR open (2).
73d8cece 142.SS File descriptor flags
cff88e99 143The following commands manipulate the flags associated with
c13182ef 144a file descriptor.
cff88e99
MK
145Currently, only one such flag is defined:
146.BR FD_CLOEXEC ,
147the close-on-exec flag.
148If the
fea681da 149.B FD_CLOEXEC
8b4be846
MK
150bit is set,
151the file descriptor will automatically be closed during a successful
152.BR execve (2).
153(If the
154.BR execve (2)
155fails, the file descriptor is left open.)
156If the
157.B FD_CLOEXEC
158bit is not set, the file descriptor will remain open across an
159.BR execve (2).
fea681da 160.TP
68e0696a 161.BR F_GETFD " (\fIvoid\fP)"
f157f403 162Return (as the function result) the file descriptor flags;
68e0696a
MK
163.I arg
164is ignored.
cff88e99 165.TP
ed9821bb 166.BR F_SETFD " (\fIint\fP)"
cff88e99 167Set the file descriptor flags to the value specified by
fea681da 168.IR arg .
2f4772d2
MK
169.PP
170In multithreaded programs, using
171.BR fcntl ()
172.B F_SETFD
173to set the close-on-exec flag at the same time as another thread performs a
174.BR fork (2)
175plus
176.BR execve (2)
177is vulnerable to a race condition that may unintentionally leak
178the file descriptor to the program executed in the child process.
179See the discussion of the
180.BR O_CLOEXEC
181flag in
182.BR open (2)
183for details and a remedy to the problem.
73d8cece 184.SS File status flags
08478724
MK
185Each open file description has certain associated status flags,
186initialized by
fea681da
MK
187.BR open (2)
188.\" or
189.\" .BR creat (2),
190and possibly modified by
2777b1ca 191.BR fcntl ().
c13182ef 192Duplicated file descriptors
cff88e99 193(made with
0bfa087b 194.BR dup (2),
cff88e99 195.BR fcntl (F_DUPFD),
0bfa087b 196.BR fork (2),
cff88e99
MK
197etc.) refer to the same open file description, and thus
198share the same file status flags.
778ac627 199.PP
cff88e99 200The file status flags and their semantics are described in
fea681da
MK
201.BR open (2).
202.TP
68e0696a 203.BR F_GETFL " (\fIvoid\fP)"
f157f403
MK
204Return (as the function result)
205the file access mode and the file status flags;
68e0696a
MK
206.I arg
207is ignored.
fea681da 208.TP
ed9821bb 209.BR F_SETFL " (\fIint\fP)"
cff88e99 210Set the file status flags to the value specified by
fea681da 211.IR arg .
c13182ef 212File access mode
cff88e99
MK
213.RB ( O_RDONLY ", " O_WRONLY ", " O_RDWR )
214and file creation flags
68b93ce2
MK
215(i.e.,
216.BR O_CREAT ", " O_EXCL ", " O_NOCTTY ", " O_TRUNC )
cff88e99 217in
fea681da
MK
218.I arg
219are ignored.
329ad271 220On Linux, this command can change only the
c13182ef 221.BR O_APPEND ,
1c1e15ed
MK
222.BR O_ASYNC ,
223.BR O_DIRECT ,
224.BR O_NOATIME ,
c13182ef 225and
0daa9e92 226.B O_NONBLOCK
1c1e15ed 227flags.
639b33d7
MK
228It is not possible to change the
229.BR O_DSYNC
230and
231.BR O_SYNC
232flags; see BUGS, below.
9584daf7 233.SS Advisory record locking
7562b10e
MK
234Linux implements traditional ("process-associated") UNIX record locks,
235as standardized by POSIX.
236For a Linux-specific alternative with better semantics,
237see the discussion of open file description locks below.
778ac627 238.PP
dc45cae3
MK
239.BR F_SETLK ,
240.BR F_SETLKW ,
241and
242.BR F_GETLK
fea681da 243are used to acquire, release, and test for the existence of record
9584daf7 244locks (also known as byte-range, file-segment, or file-region locks).
68e0696a
MK
245The third argument,
246.IR lock ,
fea681da
MK
247is a pointer to a structure that has at least the following fields
248(in unspecified order).
778ac627 249.PP
088a639b 250.in +4n
778ac627 251.EX
fea681da
MK
252struct flock {
253 ...
254 short l_type; /* Type of lock: F_RDLCK,
255 F_WRLCK, F_UNLCK */
256 short l_whence; /* How to interpret l_start:
257 SEEK_SET, SEEK_CUR, SEEK_END */
258 off_t l_start; /* Starting offset for lock */
259 off_t l_len; /* Number of bytes to lock */
260 pid_t l_pid; /* PID of process blocking our lock
99b5ab79 261 (set by F_GETLK and F_OFD_GETLK) */
fea681da
MK
262 ...
263};
778ac627 264.EE
088a639b 265.in
778ac627 266.PP
fea681da
MK
267The
268.IR l_whence ", " l_start ", and " l_len
269fields of this structure specify the range of bytes we wish to lock.
057dce78
MK
270Bytes past the end of the file may be locked,
271but not bytes before the start of the file.
778ac627 272.PP
fea681da
MK
273.I l_start
274is the starting offset for the lock, and is interpreted
275relative to either:
276the start of the file (if
277.I l_whence
278is
279.BR SEEK_SET );
280the current file offset (if
281.I l_whence
282is
283.BR SEEK_CUR );
284or the end of the file (if
285.I l_whence
286is
287.BR SEEK_END ).
288In the final two cases,
289.I l_start
290can be a negative number provided the
291offset does not lie before the start of the file.
778ac627 292.PP
fea681da 293.I l_len
057dce78
MK
294specifies the number of bytes to be locked.
295If
296.I l_len
297is positive, then the range to be locked covers bytes
298.I l_start
299up to and including
95dadb39 300.IR l_start + l_len \-1.
fea681da
MK
301Specifying 0 for
302.I l_len
303has the special meaning: lock all bytes starting at the
304location specified by
305.IR l_whence " and " l_start
306through to the end of file, no matter how large the file grows.
778ac627 307.PP
057dce78
MK
308POSIX.1-2001 allows (but does not require)
309an implementation to support a negative
310.I l_len
311value; if
312.I l_len
313is negative, the interval described by
314.I lock
315covers bytes
316.IR l_start + l_len
317up to and including
318.IR l_start \-1.
319This is supported by Linux since kernel versions 2.4.21 and 2.5.49.
778ac627 320.PP
fea681da
MK
321The
322.I l_type
323field can be used to place a read
324.RB ( F_RDLCK )
325or a write
1c287bbf 326.RB ( F_WRLCK )
fea681da
MK
327lock on a file.
328Any number of processes may hold a read lock (shared lock)
329on a file region, but only one process may hold a write lock
7c93fec0
MK
330(exclusive lock).
331An exclusive lock excludes all other locks,
fea681da
MK
332both shared and exclusive.
333A single process can hold only one type of lock on a file region;
334if a new lock is applied to an already-locked region,
8c450534 335then the existing lock is converted to the new lock type.
fea681da
MK
336(Such conversions may involve splitting, shrinking, or coalescing with
337an existing lock if the byte range specified by the new lock does not
338precisely coincide with the range of the existing lock.)
339.TP
68e0696a 340.BR F_SETLK " (\fIstruct flock *\fP)"
fea681da
MK
341Acquire a lock (when
342.I l_type
343is
344.B F_RDLCK
345or
346.BR F_WRLCK )
347or release a lock (when
348.I l_type
349is
350.BR F_UNLCK )
351on the bytes specified by the
352.IR l_whence ", " l_start ", and " l_len
353fields of
354.IR lock .
355If a conflicting lock is held by another process,
356this call returns \-1 and sets
357.I errno
358to
359.B EACCES
360or
361.BR EAGAIN .
d068eb3b
MK
362(The error returned in this case differs across implementations,
363so POSIX requires a portable application to check for both errors.)
fea681da 364.TP
68e0696a 365.BR F_SETLKW " (\fIstruct flock *\fP)"
fea681da
MK
366As for
367.BR F_SETLK ,
368but if a conflicting lock is held on the file, then wait for that
369lock to be released.
370If a signal is caught while waiting, then the call is interrupted
371and (after the signal handler has returned)
372returns immediately (with return value \-1 and
373.I errno
374set to
01538d0d
MK
375.BR EINTR ;
376see
377.BR signal (7)).
fea681da 378.TP
68e0696a 379.BR F_GETLK " (\fIstruct flock *\fP)"
fea681da
MK
380On input to this call,
381.I lock
382describes a lock we would like to place on the file.
383If the lock could be placed,
384.BR fcntl ()
385does not actually place it, but returns
386.B F_UNLCK
387in the
388.I l_type
389field of
390.I lock
391and leaves the other fields of the structure unchanged.
778ac627 392.IP
fea681da
MK
393If one or more incompatible locks would prevent
394this lock being placed, then
395.BR fcntl ()
99b5ab79 396returns details about one of those locks in the
fea681da
MK
397.IR l_type ", " l_whence ", " l_start ", and " l_len
398fields of
99b5ab79
MK
399.IR lock .
400If the conflicting lock is a traditional (process-associated) record lock,
401then the
fea681da 402.I l_pid
99b5ab79
MK
403field is set to the PID of the process holding that lock.
404If the conflicting lock is an open file description lock, then
2d3e4b83 405.I l_pid
99b5ab79
MK
406is set to \-1.
407Note that the returned information
eceaee47 408may already be out of date by the time the caller inspects it.
11ac5b51 409.PP
fea681da
MK
410In order to place a read lock,
411.I fd
412must be open for reading.
413In order to place a write lock,
414.I fd
415must be open for writing.
416To place both types of lock, open a file read-write.
778ac627 417.PP
76868835
MK
418When placing locks with
419.BR F_SETLKW ,
420the kernel detects
421.IR deadlocks ,
422whereby two or more processes have their
423lock requests mutually blocked by locks held by the other processes.
424For example, suppose process A holds a write lock on byte 100 of a file,
425and process B holds a write lock on byte 200.
426If each process then attempts to lock the byte already
427locked by the other process using
428.BR F_SETLKW ,
429then, without deadlock detection,
430both processes would remain blocked indefinitely.
431When the kernel detects such deadlocks,
432it causes one of the blocking lock requests to immediately fail with the error
433.BR EDEADLK ;
434an application that encounters such an error should release
435some of its locks to allow other applications to proceed before
436attempting regain the locks that it requires.
437Circular deadlocks involving more than two processes are also detected.
438Note, however, that there are limitations to the kernel's
439deadlock-detection algorithm; see BUGS.
778ac627 440.PP
fea681da
MK
441As well as being removed by an explicit
442.BR F_UNLCK ,
1a93af04 443record locks are automatically released when the process terminates.
11ac5b51 444.PP
fea681da
MK
445Record locks are not inherited by a child created via
446.BR fork (2),
447but are preserved across an
448.BR execve (2).
11ac5b51 449.PP
fea681da
MK
450Because of the buffering performed by the
451.BR stdio (3)
452library, the use of record locking with routines in that package
453should be avoided; use
35e21ba7 454.BR read (2)
c13182ef 455and
35e21ba7 456.BR write (2)
fea681da 457instead.
778ac627 458.PP
1a93af04
MK
459The record locks described above are associated with the process
460(unlike the open file description locks described below).
461This has some unfortunate consequences:
462.IP * 3
d9312ec7 463If a process closes
1a93af04 464.I any
d9312ec7
MK
465file descriptor referring to a file,
466then all of the process's locks on that file are released,
467regardless of the file descriptor(s) on which the locks were obtained.
1a93af04
MK
468.\" (Additional file descriptors referring to the same file
469.\" may have been obtained by calls to
470.\" .BR open "(2), " dup "(2), " dup2 "(2), or " fcntl ().)
471This is bad: it means that a process can lose its locks on
472a file such as
473.I /etc/passwd
474or
475.I /etc/mtab
476when for some reason a library function decides to open, read,
477and close the same file.
478.IP *
479The threads in a process share locks.
480In other words,
481a multithreaded program can't use record locking to ensure
97e03523 482that threads don't simultaneously access the same region of a file.
1a93af04
MK
483.PP
484Open file description locks solve both of these problems.
2d3e4b83 485.SS Open file description locks (non-POSIX)
bfb14716
MK
486Open file description locks are advisory byte-range locks whose operation is
487in most respects identical to the traditional record locks described above.
488This lock type is Linux-specific,
38702b6c 489and available since Linux 3.15.
728aff57
MK
490(There is a proposal with the Austin Group
491.\" FIXME . Review progress into POSIX
492.\" http://austingroupbugs.net/view.php?id=768
493to include this lock type in the next revision of POSIX.1.)
64515702 494For an explanation of open file descriptions, see
b7a3dc84 495.BR open (2).
778ac627 496.PP
99b5ab79
MK
497The principal difference between the two lock types
498is that whereas traditional record locks
499are associated with a process,
500open file description locks are associated with the
501open file description on which they are acquired,
502much like locks acquired with
503.BR flock (2).
504Consequently (and unlike traditional advisory record locks),
505open file description locks are inherited across
2d3e4b83 506.BR fork (2)
99b5ab79 507(and
2d3e4b83
JL
508.BR clone (2)
509with
99b5ab79
MK
510.BR CLONE_FILES ),
511and are only automatically released on the last close
512of the open file description,
513instead of being released on any close of the file.
2d3e4b83 514.PP
ee662773
MK
515Conflicting lock combinations
516(i.e., a read lock and a write lock or two write locks)
517where one lock is an open file description lock and the other
518is a traditional record lock conflict
2d3e4b83 519even when they are acquired by the same process on the same file descriptor.
778ac627 520.PP
97e03523
MK
521Open file description locks placed via the same open file description
522(i.e., via the same file descriptor,
523or via a duplicate of the file descriptor created by
524.BR fork (2),
525.BR dup (2),
bf7bc8b8 526.BR fcntl ()
97e03523
MK
527.BR F_DUPFD ,
528and so on) are always compatible:
529if a new lock is placed on an already locked region,
530then the existing lock is converted to the new lock type.
531(Such conversions may result in splitting, shrinking, or coalescing with
532an existing lock as discussed above.)
778ac627 533.PP
97e03523
MK
534On the other hand, open file description locks may conflict with
535each other when they are acquired via different open file descriptions.
536Thus, the threads in a multithreaded program can use
537open file description locks to synchronize access to a file region
538by having each thread perform its own
539.BR open (2)
540on the file and applying locks via the resulting file descriptor.
2d3e4b83 541.PP
99b5ab79
MK
542As with traditional advisory locks, the third argument to
543.BR fcntl (),
544.IR lock ,
545is a pointer to an
546.IR flock
547structure.
548By contrast with traditional record locks, the
2d3e4b83 549.I l_pid
99b5ab79
MK
550field of that structure must be set to zero
551when using the commands described below.
778ac627 552.PP
99b5ab79
MK
553The commands for working with open file description locks are analogous
554to those used with traditional locks:
2d3e4b83
JL
555.TP
556.BR F_OFD_SETLK " (\fIstruct flock *\fP)"
557Acquire an open file description lock (when
558.I l_type
559is
560.B F_RDLCK
561or
562.BR F_WRLCK )
563or release an open file description lock (when
564.I l_type
565is
566.BR F_UNLCK )
567on the bytes specified by the
568.IR l_whence ", " l_start ", and " l_len
569fields of
570.IR lock .
571If a conflicting lock is held by another process,
572this call returns \-1 and sets
573.I errno
574to
2d3e4b83
JL
575.BR EAGAIN .
576.TP
577.BR F_OFD_SETLKW " (\fIstruct flock *\fP)"
578As for
579.BR F_OFD_SETLK ,
580but if a conflicting lock is held on the file, then wait for that lock to be
99b5ab79
MK
581released.
582If a signal is caught while waiting, then the call is interrupted
583and (after the signal handler has returned) returns immediately
584(with return value \-1 and
2d3e4b83
JL
585.I errno
586set to
587.BR EINTR ;
588see
589.BR signal (7)).
590.TP
591.BR F_OFD_GETLK " (\fIstruct flock *\fP)"
592On input to this call,
593.I lock
594describes an open file description lock we would like to place on the file.
595If the lock could be placed,
596.BR fcntl ()
597does not actually place it, but returns
598.B F_UNLCK
599in the
600.I l_type
601field of
602.I lock
603and leaves the other fields of the structure unchanged.
99b5ab79
MK
604If one or more incompatible locks would prevent this lock being placed,
605then details about one of these locks are returned via
606.IR lock ,
607as described above for
608.BR F_GETLK .
d2e429c1
MK
609.PP
610In the current implementation,
611.\" commit 57b65325fe34ec4c917bc4e555144b4a94d9e1f7
612no deadlock detection is performed for open file description locks.
613(This contrasts with process-associated record locks,
614for which the kernel does perform deadlock detection.)
615.\"
73d8cece 616.SS Mandatory locking
f5cdb4b0
MK
617.IR Warning :
618the Linux implementation of mandatory locking is unreliable.
619See BUGS below.
e1124af0
MK
620Because of these bugs,
621and the fact that the feature is believed to be little used,
622since Linux 4.5, mandatory locking has been made an optional feature,
623governed by a configuration option
624.RB ( CONFIG_MANDATORY_FILE_LOCKING ).
625This is an initial step toward removing this feature completely.
778ac627 626.PP
9acee578
MK
627By default, both traditional (process-associated) and open file description
628record locks are advisory.
fea681da 629Advisory locks are not enforced and are useful only between
c13182ef 630cooperating processes.
778ac627 631.PP
9acee578 632Both lock types can also be mandatory.
c13182ef 633Mandatory locks are enforced for all processes.
00d7bbcf
MK
634If a process tries to perform an incompatible access (e.g.,
635.BR read (2)
636or
637.BR write (2))
638on a file region that has an incompatible mandatory lock,
639then the result depends upon whether the
640.B O_NONBLOCK
641flag is enabled for its open file description.
c13182ef 642If the
00d7bbcf
MK
643.B O_NONBLOCK
644flag is not enabled, then
6799ba26 645the system call is blocked until the lock is removed
00d7bbcf 646or converted to a mode that is compatible with the access.
c13182ef
MK
647If the
648.B O_NONBLOCK
00d7bbcf 649flag is enabled, then the system call fails with the error