該結構是在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 the Command parameter to the fcntl subroutine is F_SETLK orF_SETLKW, the l_type field indicates the type of lock to be created. Possible values are:
If the value of the Command parameter to the fcntl subroutine is F_GETLK, the l_type field describes an existing lock. Possible values are:
These values are defined in the unistd.h file.
l_start Defines the relative offset in bytes, measured from the starting point in the l_whence field. 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 the fcntl subroutine. This field is returned only when the value of the Command parameter is F_GETLK. l_pid Contains the ID of a process that already has a lock placed on the area defined by the fcntl subroutine. This field is returned only when the value of the Command parameter is F_GETLK.l_vfs
Specifies the file system type of the node identified in the l_sysid field.
看一下示例吧!struct flock 作為fcntl函數的第三個參數,使用F_SETLK,設置了其參數。