linux 创建锁文件
来源:互联网 发布:linux自启动shell脚本 编辑:程序博客网 时间:2024/05/21 22:57
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
int main()
{
int file_desc;
int save_errno;
file_desc = open("/tmp/LCK.test",O_RDWR|O_CREAT|O_EXCL,0444);
if(file_desc == -1)
{
save_errno = errno;
printf("open failed with error %d\n",save_errno);
}
else
{
printf("open succeeded\n");
}
exit(EXIT_SUCCESS);
}
说明:
1. 0444(零) 代表owner、group、others都有读权限。
2. Ensure that this call creates the file: if this flag is spec‐
ified in conjunction with O_CREAT, and pathname already
exists, then open() will fail.
In general, the behavior of O_EXCL is undefined if it is used
without O_CREAT.
3.save_errno = errno;
printf("open failed with error %d\n",save_errno);
save_errno是防止printf的调用影响errno的值。
- linux 创建锁文件
- Linux操作系统创建锁文件
- linux创建大文件
- linux 创建proc 文件
- linux 创建文件命令
- linux创建链接文件
- Linux创建swap文件
- Linux创建swap文件
- linux创建读写文件
- linux 创建文件映射
- linux so 文件创建
- Linux创建swap文件
- Linux创建设备文件
- linux创建文件
- Linux创建文件【命令】
- Linux命令-创建文件
- linux 创建一个文件
- linux创建空洞文件
- 预处理命令总结
- “竹影扫阶尘不动,月穿潭底水无痕”引出的……
- 内省.BeanUtils操作JavaBean
- Java ServerSocket的服务端代码介绍
- Java Socket通信读取相关信息代码
- linux 创建锁文件
- 虚拟机:解释器,树遍历解释器,基于栈与基于寄存器,大杂烩
- crs只能启动一个asm实例
- 堆和栈的区别
- hbase权威指南阅读随手笔记二之过滤器
- NSURL的用法
- 杭电 ACM 1.2.4
- 2012-12-1多校联考题 保送
- list tips