home *** CD-ROM | disk | FTP | other *** search
-
-
-
- LLLLOOOOCCCCKKKKFFFF((((3333CCCC)))) LLLLOOOOCCCCKKKKFFFF((((3333CCCC))))
-
-
-
- NNNNAAAAMMMMEEEE
- lockf - record locking on files
-
- CCCC SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- ####iiiinnnncccclllluuuuddddeeee <<<<uuuunnnniiiissssttttdddd....hhhh>>>>
-
- iiiinnnntttt lllloooocccckkkkffff ((((iiiinnnntttt ffffiiiillllddddeeeessss,,,, iiiinnnntttt ffffuuuunnnnccccttttiiiioooonnnn,,,, ooooffffffff____tttt ssssiiiizzzzeeee))));;;;
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- The _l_o_c_k_f command will allow sections of a file to be locked; advisory or
- mandatory write locks depending on the mode bits of the file [see
- _c_h_m_o_d(2)]. Locking calls from other processes which attempt to lock the
- locked file section will either return an error value or be put to sleep
- until the resource becomes unlocked. All the locks for a process are
- removed when the process terminates. [See _f_c_n_t_l(2) for more information
- about record locking.]
-
- _F_i_l_d_e_s is an open file descriptor. The file descriptor must have
- O_WRONLY or O_RDWR permission in order to establish lock with this
- function call.
-
- _F_u_n_c_t_i_o_n is a control value which specifies the action to be taken. The
- permissible values for _f_u_n_c_t_i_o_n are defined in <<<<uuuunnnniiiissssttttdddd....hhhh>>>> as follows:
-
- #define F_ULOCK 0 /* Unlock a previously locked section */
- #define F_LOCK 1 /* Lock a section for exclusive use */
- #define F_TLOCK 2 /* Test and lock a section for exclusive use */
- #define F_TEST 3 /* Test section for other processes locks */
-
-
- All other values of _f_u_n_c_t_i_o_n are reserved for future extensions and will
- result in an error return if not implemented.
-
- F_TEST is used to detect if a lock by another process is present on the
- specified section. F_LOCK and F_TLOCK both lock a section of a file if
- the section is available. F_ULOCK removes locks from a section of the
- file.
-
- _S_i_z_e is the number of contiguous bytes to be locked or unlocked. The
- resource to be locked starts 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 _s_i_z_e is
- zero, the section from the current offset through the largest file offset
- is locked (i.e., from the current offset through the present or any
- future end-of-file). An area need not be allocated to the file in order
- to be locked as such 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 sections occur, the sections
- are combined into a single section. If the request requires that a new
- element be added to the table of active locks and this table is already
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- LLLLOOOOCCCCKKKKFFFF((((3333CCCC)))) LLLLOOOOCCCCKKKKFFFF((((3333CCCC))))
-
-
-
- full, an error is returned, and the new section is not locked.
-
- F_LOCK and F_TLOCK requests differ only by the action taken if the
- resource is not available. F_LOCK will cause the calling process to
- sleep until the resource is available. F_TLOCK will cause the function
- to return a -1 and set _e_r_r_n_o to [EACCES] error if the section is already
- locked by another process.
-
- F_ULOCK requests may, in whole or in part, release one or more locked
- sections controlled by the process. When sections are not fully
- released, the remaining sections are still locked by the process.
- Releasing the center section of a locked section requires an additional
- element in the table of active locks. If this table is full, an
- [EDEADLK] error is returned and the requested section is not released.
-
- A potential for deadlock occurs if a process controlling a locked
- resource is put to sleep by accessing another process's locked resource.
- Thus calls to _l_o_c_k_f or _f_c_n_t_l scan for a deadlock prior to sleeping on a
- locked resource. An error return is made if sleeping on the locked
- resource would cause a deadlock.
-
- Sleeping on a resource is interrupted with any signal. The _a_l_a_r_m(2)
- command may be used to provide a timeout facility in applications which
- require this facility.
-
- The _l_o_c_k_f utility will fail if one or more of the following are true:
-
-
- [EBADF]
- _F_i_l_d_e_s is not a valid open file.
-
- [EACCES]
- _C_m_d is F_TLOCK or F_TEST and the section is already locked by
- another process.
-
- [EDEADLK]
- _C_m_d is F_LOCK and a deadlock would occur. Also the _c_m_d is either
- F_LOCK, F_TLOCK, or F_ULOCK and the number of entries in the lock
- table would exceed the number allocated on the system.
-
- NNNNOOOOTTTTEEEESSSS
- Locks are on files, not file descriptors. That is, file descriptors
- duplicated through _d_u_p(3C) do not result in multiple instances of locks,
- but rather multiple references to the same locks. Thus if any of the
- descriptors associated with the same file are closed, the locks
- associated with the file are lost.
-
- SSSSEEEEEEEE AAAALLLLSSSSOOOO
- chmod(2), close(2), creat(2), fcntl(2), intro(2), open(2), read(2),
- write(2).
-
-
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-
-
-
- LLLLOOOOCCCCKKKKFFFF((((3333CCCC)))) LLLLOOOOCCCCKKKKFFFF((((3333CCCC))))
-
-
-
- DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
- Upon successful completion, a value of 0 is returned. Otherwise, a value
- of -1 is returned and _e_r_r_n_o is set to indicate the error.
-
- WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS
- Unexpected results may occur in processes that do buffering in the user
- address space. The process may later read/write data which is/was
- locked. The standard I/O package is the most common source of unexpected
- buffering.
-
- Because in the future the variable _e_r_r_n_o will be set to EAGAIN rather
- than EACCES when a section of a file is already locked by another
- process, portable application programs should expect and test for either
- value.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 3333
-
-
-
-