281 lines
6.0 KiB
HTML
281 lines
6.0 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of LOCKF</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>LOCKF</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
lockf - apply, test or remove a POSIX lock on an open file
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>></B>
|
|
|
|
<P>
|
|
|
|
<B>int lockf(int </B><I>fd</I><B>, int </B><I>cmd</I><B>, off_t </B><I>len</I><B>);</B>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>lockf</B>():
|
|
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
_XOPEN_SOURCE >= 500
|
|
|
|
<BR> || /* Glibc since 2.19: */ _DEFAULT_SOURCE
|
|
<BR> || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
Apply, test or remove a POSIX lock on a section of an open file.
|
|
The file is specified by
|
|
<I>fd</I>,
|
|
|
|
a file descriptor open for writing, the action by
|
|
<I>cmd</I>,
|
|
|
|
and the section consists of byte positions
|
|
<I>pos</I>..<I>pos</I>+<I>len</I>-1
|
|
|
|
if
|
|
<I>len</I>
|
|
|
|
is positive, and
|
|
<I>pos</I>-<I>len</I>..<I>pos</I>-1
|
|
|
|
if
|
|
<I>len</I>
|
|
|
|
is negative, where
|
|
<I>pos</I>
|
|
|
|
is the current file position, and if
|
|
<I>len</I>
|
|
|
|
is zero, the section extends from the current file position to
|
|
infinity, encompassing the present and future end-of-file positions.
|
|
In all cases, the section may extend past current end-of-file.
|
|
<P>
|
|
|
|
On Linux,
|
|
<B>lockf</B>()
|
|
|
|
is just an interface on top of
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fcntl">fcntl</A></B>(2)
|
|
|
|
locking.
|
|
Many other systems implement
|
|
<B>lockf</B>()
|
|
|
|
in this way, but note that POSIX.1 leaves the relationship between
|
|
<B>lockf</B>()
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fcntl">fcntl</A></B>(2)
|
|
|
|
locks unspecified.
|
|
A portable application should probably avoid mixing calls
|
|
to these interfaces.
|
|
<P>
|
|
|
|
Valid operations are given below:
|
|
<DL COMPACT>
|
|
<DT id="2"><B>F_LOCK</B>
|
|
|
|
<DD>
|
|
Set an exclusive lock on the specified section of the file.
|
|
If (part of) this section is already locked, the call
|
|
blocks until the previous lock is released.
|
|
If this section overlaps an earlier locked section,
|
|
both are merged.
|
|
File locks are released as soon as the process holding the locks
|
|
closes some file descriptor for the file.
|
|
A child process does not inherit these locks.
|
|
<DT id="3"><B>F_TLOCK</B>
|
|
|
|
<DD>
|
|
Same as
|
|
<B>F_LOCK</B>
|
|
|
|
but the call never blocks and returns an error instead if the file is
|
|
already locked.
|
|
<DT id="4"><B>F_ULOCK</B>
|
|
|
|
<DD>
|
|
Unlock the indicated section of the file.
|
|
This may cause a locked section to be split into two locked sections.
|
|
<DT id="5"><B>F_TEST</B>
|
|
|
|
<DD>
|
|
Test the lock: return 0 if the specified section
|
|
is unlocked or locked by this process; return -1, set
|
|
<I>errno</I>
|
|
|
|
to
|
|
<B>EAGAIN</B>
|
|
|
|
(<B>EACCES</B>
|
|
|
|
on some other systems),
|
|
if another process holds a lock.
|
|
</DL>
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, zero is returned.
|
|
On error, -1 is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="6"><B>EACCES</B> or <B>EAGAIN</B>
|
|
|
|
<DD>
|
|
The file is locked and
|
|
<B>F_TLOCK</B>
|
|
|
|
or
|
|
<B>F_TEST</B>
|
|
|
|
was specified, or the operation is prohibited because the file has
|
|
been memory-mapped by another process.
|
|
<DT id="7"><B>EBADF</B>
|
|
|
|
<DD>
|
|
<I>fd</I>
|
|
|
|
is not an open file descriptor; or
|
|
<I>cmd</I>
|
|
|
|
is
|
|
<B>F_LOCK</B>
|
|
|
|
or
|
|
<B>F_TLOCK</B>
|
|
|
|
and
|
|
<I>fd</I>
|
|
|
|
is not a writable file descriptor.
|
|
<DT id="8"><B>EDEADLK</B>
|
|
|
|
<DD>
|
|
The command was
|
|
<B>F_LOCK</B>
|
|
|
|
and this lock operation would cause a deadlock.
|
|
<DT id="9"><B>EINTR</B>
|
|
|
|
<DD>
|
|
While waiting to acquire a lock, the call was interrupted by
|
|
delivery of a signal caught by a handler; see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7).
|
|
|
|
<DT id="10"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
An invalid operation was specified in
|
|
<I>cmd</I>.
|
|
|
|
<DT id="11"><B>ENOLCK</B>
|
|
|
|
<DD>
|
|
Too many segment locks open, lock table is full.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>lockf</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SVr4.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fcntl">fcntl</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+flock">flock</A></B>(2)
|
|
|
|
<P>
|
|
|
|
<I>locks.txt</I>
|
|
|
|
and
|
|
<I>mandatory-locking.txt</I>
|
|
|
|
in the Linux kernel source directory
|
|
<I>Documentation/filesystems</I>
|
|
|
|
(on older kernels, these files are directly under the
|
|
<I>Documentation</I>
|
|
|
|
directory, and
|
|
<I>mandatory-locking.txt</I>
|
|
|
|
is called
|
|
<I>mandatory.txt</I>)
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="12"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="13"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="14"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="15"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="16"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="17"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="18"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="19"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
<DT id="20"><A HREF="#lbAJ">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:47 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|