fcntl flock文件记录锁

fcntl flock
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
int FileUnLock(int fd_lock)
{
	struct flock strLock;
	strLock.l_type = F_UNLCK;
	strLock.l_whence = SEEK_SET;
	strLock.l_start = 0;
	strLock.l_len = 0;
	return fcntl(fd_lock,F_SETLK,&strLock);
}
int FileSetLock(int fd_lock)
{
	struct flock strLock;
	//	strLock.l_type = F_WRLCK;
	strLock.l_type = F_RDLCK;
	strLock.l_whence = SEEK_SET;
	strLock.l_start = 0;
	strLock.l_len = 0;
	return fcntl(fd_lock,F_SETLK,&strLock);
}

 fopen打开函数

int fd = 0;

    fd = fileno()

posted on 2021-03-09 21:23  lydstory  阅读(79)  评论(0)    收藏  举报

导航