int lockf(int fildes, int cmd, off_t size);
int lockf64(int fildes, int cmd, off64_t size);
The following lock commands are available:
Unlock a previously locked section of the file.
Lock a section for exclusive use. If the section is already locked by another process, wait until it is available, or until
lockf()is interrupted by a signal.
Test a section for another process' locks. If the section is already locked, return a failure rather than blocking until the lock becomes available
Test a section for another process' locks.
The section to be locked or unlocked starts at the current offset in the file and extends forward for a positive size or backward for a negative size (the preceding bytes up to but not including the current offset). If the specified lock size is 0, the section from the current offset through the largest possible file offset is locked. An area need not be allocated to the file to be locked because locks may exist past the end-of-file.
The sections locked with F_LOCK or F_TLOCK may, in whole or in part, contain or be contained by a previously locked section for the same process. When this occurs, or if adjacent locked sections would occur, the sections are combined into a single locked section. If the request would cause the number of locks to exceed a system-imposed limit, the request fails.
File locks are released on the first close by the locking process of any file descriptor for the file.
The F_ULOCK request may release (wholly or in part) one or more locked sections controlled by the process. Locked sections are unlocked starting at the current file offset through the specified size bytes , or to the end of file if the size is 0. When all of a locked section is not released, the remaining portions of that section are still locked by the process. Releasing the center portion of a locked section causes the remaining locked beginning and end portions to become two separate locked sections. If the request would cause the number of locks in the system to exceed a system-imposed limit, the request fails.
A potential for deadlock occurs
if the threads of a process controlling a locked section are
blocked by accessing another process' locked section. If the
system detects that deadlock would occur,
Is an open file descriptor. It must have O_WRONLY or O_RDWR permission for a successful locking call.
Is a lock command, as described in the DESCRIPTION section.
Is the number of contiguous bytes to be locked or unlocked.
The cmd parameter is F_TLOCK or F_TEST and the section is already locked by another process.
The fildes parameter is not a valid open descriptor. Or, the cmd parameter is F_LOCK or F_TLOCK and the fildes argument is not a valid file descriptor open for writing.
The cmd parameter is F_LOCK, the lock is blocked by some lock from another process, and putting the calling process to sleep, waiting for that lock to become free would cause a deadlock.
The cmd parameter is F_LOCK and a signal interrupted the process while it was waiting to complete the lock.
The cmd parameter is not one of F_LOCK, F_TLOCK, F_TEST, or F_ULOCK.
The size parameter plus the current file offset is less than 0.
The fildes parameter refers to a file that does not support locking.
The cmd parameter is F_LOCK, F_TLOCK, or F_ULOCK and the number of locked regions available in the system would be exceeded by the request.
The offset of the first, or if size is not 0 then the last byte in the requested section cannot be represented correctly in an object of type off_t.
Standard locks apply only to the local system.
Locks are, by default, advisory. The NuTCRACKER Platform also supports a form of mandatory
locking on 2012/8.1/2012R2/10/2016/2019.
If the S_ISGID access mode bit is set for a file, and
S_IXGRP is not set, then the NuTCRACKER Platform enables mandatory locking
for the file using Win32 APIs.
Mandatory locks are not inherited across
The NuTCRACKER Platform also supports an advisory locking mode
that uses the native Win32 locking APIs (
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
_NutConf(), _NutForkExecl(), _NutForkExecle(), _NutForkExeclp(), _NutForkExeclpe(), _NutForkExecv(), _NutForkExecve(), _NutForkExecvp(), _NutForkExecvpe(), chmod(), execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), fcntl(), fork()
PTC MKS Toolkit 10.3 Documentation Build 39.