该结构是在lock.h文件中定义。
lock.h File
功能
定义一些文件的锁的选项
Description
The flock structure in the /usr/include/sys/flock.h file, which describes a lock, contains the following fields:
l_type
Describes the type of lock. If the value of theCommandparameter to thefcntlsubroutine isF_SETLKorF_SETLKW, thel_typefield indicates the type of lock to be created. Possible values are:
F_RDLCK
A read lock is requested.
F_WRLCK
A write lock is requested.
F_UNLCK
Unlock. An existing lock is to be removed. If the value of theCommandparameter to thefcntlsubroutine isF_GETLK, thel_typefield describes an existing lock. Possible values are: These values are defined in theunistd.hfile. l_vfs Specifies the file system type of the node identified in thel_sysidfield.
l_whence
Defines the starting offset. The value of this field indicates the point from which the relative offset, thel_startfield, is measured. Possible values are:
SEEK_SET
The relative offset is measured from the start of the file.
SEEK_CUR
The relative offset is measured from the current position.
SEEK_END
The relative offset is measured from the end of the file.
l_start
Defines the relative offset in bytes, measured from the starting point in thel_whencefield.
l_len
Specifies the number of consecutive bytes to be locked.
l_sysid
Contains the ID of the node that already has a lock placed on the area defined by thefcntlsubroutine. This field is returned only when the value of theCommandparameter isF_GETLK.
l_pid
Contains the ID of a process that already has a lock placed on the area defined by thefcntlsubroutine. This field is returned only when the value of theCommandparameter isF_GETLK.
看一下示例吧!