United States-English |
|
|
HP-UX Reference > Fflock(2)HP-UX 11i Version 3: February 2007 |
|
NAMEflock() — apply or remove an advisory or enforced lock on an open file SYNOPSIS#include <sys/fcntl.h> int flock(int filedes, int operation); Parameters
DESCRIPTIONThe flock() function applies or removes an advisory or enforced lock on the whole file associated with the filedes file descriptor. Advisory locks allow cooperating processes to perform consistent operations on files, but do not guarantee consistency (that is, processes may still access files without using advisory locks, possibly resulting in inconsistencies).Enforced locks are in effect if the enforcement bit in the file mode is set (see chmod(2)). This might affect read(), write(), and other system calls performing file operations. You can use the flock() function to coordinate a file's lock status on local and NFS file systems. The locking mechanism allows two types of locks: shared locks and exclusive locks. At any time multiple shared locks may be applied to a file, but at no time are multiple exclusive locks or both shared and exclusive locks allowed simultaneously on a file. A shared lock may be upgraded to an exclusive lock, and vice versa, simply by specifying the appropriate lock type. This results in the previous lock being released and the new lock applied (possibly after other processes have gained and released the lock). Requesting a lock on an object that is already locked normally causes the caller to be blocked until the lock may be acquired. If LOCK_NB is included in operation, this will not happen; instead, the call will fail and errno will be set to EWOULDBLOCK. APPLICATION USAGELocks are on files, not file descriptors. This means that:
Processes that are blocked awaiting a lock may be awakened by signals. An application needs to check the return value to make sure that the lock is really acquired. The flock() interface is not part of any UNIX standard. Therefore, if you are designing and writing applications to be portable across platforms, you should use the fcntl() file locking interface instead of flock(). NETWORKING FEATURESNFSThe advisory file locking capabilities of flock() are implemented throughout the network by the network lock daemon (lockd). If the file server crashes and is rebooted, the lock daemon attempts to recover all locks associated with the crashed server. If a lock cannot be reclaimed, the process that held the lock is issued a SIGLOST signal. See lockd(1M). File locking as implemented for NFS files is only advisory. RETURN VALUESflock() returns:
ERRORSIf the flock() function fails, errno may be set to one of the following values:
|
Printable version | ||
|