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()
浙公网安备 33010602011771号