Syntax | #include <unistd.h> int lockf(int fildes, int function, off_t size); | |
Description |
fildes is an open file descriptor. The file descriptor must have function is control value which specifies the measures to be taken. The permissible values for function are defined as follows in #define F_ULOCK 0 /* Release locked section */ #define F_LOCK 1 /* Lock section exclusively */ #define F_TLOCK 2 /* Test section and lock it exclusively */ #define F_TEST 3 /* Test section for locks of other processes */ All other values of function are reserved for future extensions and lead to an error message if they are not implemented.
size is the number of contiguous bytes to be locked or unlocked. The resource to be locked or unlocked begins at the current offset in the file and extends forward for a positive size and backward for a negative size (the preceding bytes up to but not including the current offset). If size is zero, the section from the current offset to the largest file offset is locked, i.e. from the current offset up to the current or any future end of file. An area does not need to be allocated to a file in order to be locked, because these locks can also extend beyond the end of the file. The sections locked with The requirements of Locked sections are released by the first
A deadlock situation can arise if a process that controls a locked resource is made to pause by a request for the locked resource of another process. Therefore when Simultaneous locking with The waiting for a resource is interrupted with a random signal. The
There is no difference in functionality between If threads are used, then the function affects the process or a thread in the following manner: File section is locked, lock calls from other threads that attempt to lock a file section that is already locked will result in the return of an error number or the calling thread will be blocked until the section is released. All locks for a process are deleted when the process is terminated. | |
Return val. | 0 | if successful. |
-1 | if an error occurs. | |
Errors |
| |
|
| fildes is not a valid open file descriptor, or function is |
|
| function is |
|
| function is |
|
| A signal was caught during execution of the function. |
|
| function is |
|
| function is |
|
| fildes points to a file type that cannot be locked in this implementation, or the contents of function are invalid, or the sum of size plus the current file offset is less than 0 or greater than the highest permissible file offset. |
|
| fildes is on a remote computer and the link to this computer is no longer active. |
|
| The offset of the first byte or, when the size is not equal to 0, the last byte in the requested section cannot be represented correctly in an object of type |
Notes | Unexpected events can occur in processes that buffer in the address space of the user. The process can later read or write data that is or was locked. The standard I/O package is the most common cause of unexpected buffering. Instead of this, simpler functions should be used which work unbuffered, e.g. Because the The | |
See also |
|