lk.l_whence=SEEK_SET;是什么意思?

1个回答

  • 这是flock的l_whence域吧?它用来表示l_start的含义,如果l_whence=SEEK_SET,那么l_start就是从文件头开始计算的偏移值.

    如果l_whence=SEEK_CUR,那么l_start表示从文件当前指针位置开始计算的偏移值,如果为SEEK_END,那么l_start为从文件尾向前移动的偏移值.

    The l_whence, l_start, and l_len fields of this structure specify the

    range of bytes we wish to lock. l_start is the starting offset for the

    lock, and is interpreted relative to either: the start of the file (if

    l_whence is SEEK_SET); the current file offset (if l_whence is

    SEEK_CUR); or the end of the file (if l_whence is SEEK_END). In the

    final two cases, l_start can be a negative number provided the offset

    does not lie before the start of the file.

    linux下可用man 2 fcntl看到这些内容.