C语言文件锁

此页面是否是列表页或首页?未找到合适正文内容。

C语言文件锁

标签:encgeserrpathclose技术分享modetypesint

mkfifo.c文件

1 #include<sys/types.h>
2 #include<sys/stat.h>
3 #include<stdio.h>
4 #include<errno.h>
5
6 int main()
7 {
8 //int mkfifo(const char *pathname, mode_t mode);
9
10 int ret=mkfifo(\”./test\”,0777);
11 if(ret<0)
12 {
13 if(errno==EEXIST)
14 {
15 printf(\”create error errno=%d\\n\”,errno);
16 return -1;
17 }
18 }
19 }

file_read.c文件

1 #include<unistd.h>
2 #include<fcntl.h>
3 #include<stdio.h>
4 #include<errno.h>
5 int main()
6 {
7 int fd;
8 fd=open(\”./test\”,O_RDONLY);
9 if(fd<0)
10 {
11 perror(\”open failed\\n\”);
12 return -1;
13 }
14
15 //int fcntl(int fd,int cmd,…/* arg */ );
16 //设置读锁
17 struct flock lock;
18 lock.l_type=F_RDLCK;
19 lock.l_whence=SEEK_SET;
20 lock.l_start=0;

作者: liuzhihao

为您推荐

返回顶部