#include <iostream>
#include <fcntl.h>
using namespace std;
int main(int argc, char* argv[])
{
int fd = open("a.txt", O_RDWR|O_CREAT, 0777);
if(fd<0)
{
cout<<"open error"<<endl;
return -1;
}
struct flock arg;
arg.l_type = F_RDLCK;
arg.l_whence = SEEK_SET;
arg.l_start = 0;
arg.l_len = 20;
fcntl(fd, F_SETLKW, arg);
}
#include <fcntl.h>
using namespace std;
int main(int argc, char* argv[])
{
int fd = open("a.txt", O_RDWR|O_CREAT, 0777);
if(fd<0)
{
cout<<"open error"<<endl;
return -1;
}
struct flock arg;
arg.l_type = F_RDLCK;
arg.l_whence = SEEK_SET;
arg.l_start = 0;
arg.l_len = 20;
fcntl(fd, F_SETLKW, arg);
}