⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flock.2

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 2
字号:
.\" SCCSID: @(#)flock.2	8.1	9/11/90.TH flock 2.SH Nameflock \- apply or remove an advisory lock on an open file.SH Syntax.nf.ft B#include <sys/file.h>.PP.ft B.DT#define	LOCK_SH	1	/* shared lock */#define	LOCK_EX	2	/* exclusive lock */#define	LOCK_NB	4	/* don't block when locking */#define	LOCK_UN	8	/* unlock */.PP.ft Bflock(fd, operation)int fd, operation;.fi.SH Description.NXR "flock system call".NXR "file" "applying advisory lock"The.PN flocksystem call applies or removes an.I advisorylock on the file associated with the file descriptor,.IR fd .A lock is applied by specifying an.I operationparameter that is the inclusive OR ofLOCK_SH or LOCK_EX and, possibly, LOCK_NB.  To unlockan existing lock,.I operationshould be LOCK_UN..PPAdvisory locks allow cooperating processes to performconsistent operations on files, but do not guaranteeconsistency; that is, processes might still access fileswithout using advisory locks, possibly resulting ininconsistencies..NXR "advisory lock" "defined".PPThe locking mechanism allows two types of locks:.I sharedlocks and.I exclusivelocks.At any time, multiple shared locks can be applied to a file.However, multiple exclusive locks, or shared and exclusivelocks cannot be applied simultaneously on a file.  .PPA shared lock can beupgraded to be an exclusive lock, and an exclusive lock can become shared, simply by specifyingthe appropriate lock type. This change results in the previouslock being released and the new lock applied. When upgrading,do not include LOCK_NB in.IR operation,because there is a possibility that other processes haverequests for locks, or have gained or released a lock..PPRequesting a lock on an object that is already lockednormally causes the caller to blocked until the lock can beacquired.  If LOCK_NB is included in.IR operation ,the call is not blocked; instead, the call fails andthe error EWOULDBLOCK is returned..PPLocks are on files, not file descriptors.  That is, file descriptorsduplicated through .PN dup or.PN fork call do not result in multiple instances of a lock, but rather multiplereferences to a single lock.  If a process holding a lock on a fileforks and the child explicitly unlocks the file, the parent loses its lock..PPProcesses blocked awaiting a lock may be awakened by signals..SH Return ValuesZero is returned if the operation was successful;on an error, a \-1 is returned and an error code is stored inthe global variable, \fIerrno\fP..SH DiagnosticsThe .PN flockcall fails under the following conditions: .TP 15[EWOULDBLOCK]The file is locked and the LOCK_NB option was specified..TP 15[EBADF]The argument \fIfd\fP is an invalid descriptor..TP 15[EINVAL]The argument \fIfd\fP refers to an object other than a file..TP 15[EOPNOTSUPP]Invalid operation is requested.  The argument \fIfd\fRrefers to a socket..SH RestrictionsFile region locking is not supported over NFS..SH See Alsoclose(2), dup(2), execve(2), fork(2), open(2)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -