Linux 文件符操作
来源:互联网 发布:mac 任务管理工具 编辑:程序博客网 时间:2024/06/05 04:07
2.3 读写文件
fd = open();
write(); // Linux
读
int fd;fd=open(argv[1],O_RDWR); if(-1==fd){ perror("open"); return -1;}int ret;ret = read(); // 返回0if(ret<=0){ perror("read");}puts();
// 循环读取
bzero(file,sizeof(c))
write(fd,c,sizeof(c)) // 写到屏幕
2.5 文件当前位置
ftell() // c 返回当前位置
lseek(int fd,off_t offset, int whence); // Linux
int fseek(FILE *stream,long offset,int oregin)
%!xxd // 以16进制查看
2.7 文件的复制
内核数据拷贝 、、 接口
dup 复制到下一块当前最小
引用计数 ARC==0 时关闭 free 销毁
自动垃圾回收 GC
0 only_read
1 only_write
int dup(int oldfd); // 默认最小位置
int dup2(itn oldfd,int newfd); // 指定到已经打开的位置
不同之处newfd在执行dup2之前会被关闭,最后返回newfd
在读同一个描述符时候需要偏移,
lseek(,0,SEEK_SET);
两个指向同一块的时候,需要偏移才能读出。存放了两个位置,内容只有一份。
2.9 I/O 多路转接
mkfifo test.fifo // 创建管道文件
1.管道通信,等两端信息进入管道
利用fork机制建立,
// case 1 pipe 读取内容
管道半双工:
1. 写端不阻塞
断开管道:
read 返回值为0,结束
while(memset(buf,0,sizeof(buf)),read(STDIN_FILENO,buf,sizeof(buf)){
write(fdw,buf,strlen(buf)-1); // \n
}
死锁问题:
管道传参一致,避免死锁
while 实现循环读取
int select(int maxfd,fd_set *readset,); // 监管
// 定义集合
FD_ZERO(&);
- Linux 文件符操作
- Linux 文件测试操作符
- Linux文件描述符的简单操作
- Linux Bash 字符串/布尔/文件操作符
- linux文件操作
- linux文件操作备忘录
- Linux shell__文件操作
- Linux文件操作常用命令
- linux 临时性文件操作
- Linux文件操作篇
- linux文件相关操作
- linux--文件操作命令
- linux 文件操作
- Linux文件基本操作
- linux 文件操作 简介
- linux 文件操作指令
- linux文件操作
- Linux文件操作
- 解密Java内存溢出之持久代
- Java笔记 - IO流(FileReader,FileWriter)
- 231. Power of Two
- 深挖SpringMVC_07_ 细说org.springframework.context.ApplicationContextAware
- 1013. 数素数 (20)
- Linux 文件符操作
- 找出两个链表的交叉点
- keychain
- LeetCode 257. Binary Tree Paths
- 小学生算术
- [BZOJ4551][Tjoi2016&Heoi2016]树 dfs序+线段树
- HDU 1043 Eight ((八数码问题)逆向BFS + 康托定理判重)
- leetcode 随机概率 水塘抽样
- PAT甲级1071