当前位置: 技术问答>linux和unix
文件加锁问题
来源: 互联网 发布时间:2016-07-12
本文导语: #include #include #include #include #include #include #include #include typedef struct { char *GET1; char *GET2; }GETX_T; GETX_T Test(char *str) { GETX_T TestGet; STR PMode = Divide_Para(str); pid_t pid; int i, val; char buf[20]; memset(...
#include
#include
#include
#include
#include
#include
#include
#include
typedef struct
{
char *GET1;
char *GET2;
}GETX_T;
GETX_T Test(char *str)
{
GETX_T TestGet;
STR PMode = Divide_Para(str);
pid_t pid;
int i, val;
char buf[20];
memset(buf, '', sizeof(buf));
creat("/home/zzh/Desktop/Mmap/010", PMode.mode);
int fd = open("/home/zzh/Desktop/Mmap/010", O_RDWR);
write(fd, "Dawning", sizeof("Dawning"));
struct flock lock;
lock.l_type = F_RDLCK;
lock.l_start = 0;
lock.l_whence = SEEK_SET;
lock.l_len = sizeof(buf);
if((pid = fork()) 0)
{
if(fcntl(fd, F_GETLK, &lock)
#include
#include
#include
#include
#include
#include
#include
typedef struct
{
char *GET1;
char *GET2;
}GETX_T;
GETX_T Test(char *str)
{
GETX_T TestGet;
STR PMode = Divide_Para(str);
pid_t pid;
int i, val;
char buf[20];
memset(buf, '', sizeof(buf));
creat("/home/zzh/Desktop/Mmap/010", PMode.mode);
int fd = open("/home/zzh/Desktop/Mmap/010", O_RDWR);
write(fd, "Dawning", sizeof("Dawning"));
struct flock lock;
lock.l_type = F_RDLCK;
lock.l_start = 0;
lock.l_whence = SEEK_SET;
lock.l_len = sizeof(buf);
if((pid = fork()) 0)
{
if(fcntl(fd, F_GETLK, &lock)