lockf(3) Library Functions Manual lockf(3)

lockf - aplica, comprueba o elimina un bloqueo POSIX sobre un fichero abierto

Biblioteca Estándar C (libc, -lc)

#include <unistd.h>
int lockf(int fd, int cmd, off_t len);
Requisitos de Macros de Prueba de Características para glibc (véase feature_test_macros(7)):

lockf():

    _XOPEN_SOURCE >= 500
        || /* glibc >= 2.19: */ _DEFAULT_SOURCE
        || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

Apply, test, or remove a POSIX lock on a section of an open file. The file is specified by fd, a file descriptor open for writing, the action by cmd, and the section consists of byte positions pos..pos+len-1 if len is positive, and pos-len..pos-1 if len is negative, where pos is the current file position, and if len 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.

On Linux, lockf() is just an interface on top of fcntl(2) locking. Many other systems implement lockf() in this way, but note that POSIX.1 leaves the relationship between lockf() and fcntl(2) locks unspecified. A portable application should probably avoid mixing calls to these interfaces.

Las operaciones válidas son:

Establece un bloqueo exclusivo en la sección especificada del fichero. Si (parte de) esta sección ya está bloqueada, la llamada se bloquea hasta que el bloqueo anterior sea liberado. Si esta sección se solapa con una sección previamente bloqueada, ambas se fusionan. Los bloqueos sobre el fichero son liberados tan pronto como el proceso que mantiene los bloqueos cierre algunos descriptores de fichero para el fichero. Un proceso hijo no hereda estos bloqueos.
Igual que F_LOCK pero la llamada nunca se bloquea y devuelve un error en su lugar si el fichero ya está bloqueado.
Desbloquea la sección indicada del fichero. Ésto puede provocar que una sección bloqueada se divida en dos secciones bloqueadas.
Test the lock: return 0 if the specified section is unlocked or locked by this process; return -1, set errno to EAGAIN (EACCES on some other systems), if another process holds a lock.

En caso de éxito se devuelve cero. En caso de error se devuelve -1, y errno se configura para indicar el error.

El fichero está bloqueado y se especificó F_TLOCK o F_TEST, o se prohibe la operación porque el fichero ha sido ubicado en memoria por otro proceso.
fd is not an open file descriptor; or cmd is F_LOCK or F_TLOCK and fd is not a writable file descriptor.
La orden fue F_LOCK y esta operación de bloqueo causaría una situación de interbloqueo.
While waiting to acquire a lock, the call was interrupted by delivery of a signal caught by a handler; see signal(7).
Se especificó una operación inválida en cmd.
Demasiados bloqueos de segmento abiertos, la tabla de bloqueos está llena.

Para obtener una explicación de los términos usados en esta sección, véase attributes(7).

Interfaz Atributo Valor
lockf() Seguridad del hilo Multi-hilo seguro

POSIX.1-2008.

POSIX.1-2001, SVr4.

fcntl(2), flock(2)

locks.txt and mandatory-locking.txt in the Linux kernel source directory Documentation/filesystems (on older kernels, these files are directly under the Documentation directory, and mandatory-locking.txt is called mandatory.txt)

La traducción al español de esta página del manual fue creada por Miguel Pérez Ibars <mpi79470@alu.um.es>

Esta traducción es documentación libre; lea la GNU General Public License Version 3 o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD.

Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a debian-l10n-spanish@lists.debian.org.

31 Octubre 2023 Páginas de manual de Linux 6.06