当前位置: 技术问答>linux和unix
关于记录锁的struct flock结构中返回的pid问题
来源: 互联网 发布时间:2017-02-22
本文导语: 1.c /**************************************************************************************/ /* 关于记录锁的struct flock结构中返回的pid问题 返回的不是持有锁的那个进程ID吗? */ /*******************************************************************...
1.c
/**************************************************************************************/
/*
关于记录锁的struct flock结构中返回的pid问题
返回的不是持有锁的那个进程ID吗?
*/
/*************************************************************************************/
#include
#include
#include
#include
#include "SynchroProcess.h"
int lock_reg(int fd, int cmd, int l_type, off_t l_start,
short where, off_t l_len)
{
struct flock lock;
lock.l_type = l_type;
lock.l_whence = where;
lock.l_start = l_start;
lock.l_len = l_len;
return fcntl(fd, cmd, &lock);
}
#define read_lock(fd, offset, where, len)
lock_reg(fd, F_SETLK, F_RDLCK, offset, where, len)
#define readw_lock(fd, offset, where, len)
lock_reg(fd, F_SETLKW, F_RDLCK, offset, where, len)
#define write_lock(fd, offset, where, len)
lock_reg(fd, F_SETLK, F_WRLCK, offset, where, len)
#define writew_lock(fd, offset, where, len)
lock_reg(fd, F_SETLKW, F_WRLCK, offset, where, len)
#define un_lock(fd, offset, where, len)
lock_reg(fd, F_SETLK, F_UNLCK, offset, where, len)
pid_t lock_test(int fd, int type, off_t start,
short where, off_t len)
{
struct flock lock;
lock.l_type = type;
lock.l_start = start;
lock.l_whence = where;
lock.l_len = len;
if (fcntl(fd, F_GETFL, &lock)