int fcntl(int filedes, int cmd, ... /* struct
flock *flockptr */ );
Returns: depends on cmd if OK (see following), 1 on error
For record locking, cmd is F_GETLK, F_SETLK, or F_SETLKW. The third argument (which we'll call flockptr) is a pointer to an flock structure.
struct flock {
short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */
off_t l_start; /* offset in bytes, relative to l_whence */
short l_whence; /* SEEK_SET, SEEK_CUR, or SEEK_END */
off_t l_len; /* length, in bytes; 0 means lock to EOF */
pid_t l_pid; /* returned with F_GETLK */
};
This structure describes
The type of lock desired: F_RDLCK (a shared read lock), F_WRLCK (an exclusive write lock), or F_UNLCK (unlocking a region)
The starting byte offset of the region being locked or unlocked (l_start and l_whence)
The size of the region in bytes (l_len)
The ID (l_pid) of the process holding the lock that can block the current process (returned by F_GETLK only)作者: lanying_wzw 時間: 2008-08-09 21:58
用fcntl()文件鎖作者: net_robber 時間: 2008-08-10 00:18
如果B進程是你自己寫的,那么當你不希望B進程對文件進行寫操作的時候,為什么會在B進程中加入寫文件的代碼???