Linux System Programming 学习笔记(三) 标准缓冲I/O
1. partial block operations are inefficient.
The operating system has to “fix up” your I/O by ensuring that everything occurs on block-aligned boundaries and rounding up to the next largest block
2. User-buffered I/O
#include <stdio.h> int main(int argc, char* argv[])
{
struct private {
char name[]; /* real name */
unsigned long booty; /* in pounds sterling */
unsigned int beard_len; /* in inches */
};
struct private p;
struct private blackbeard = {"Edward Teach", , }; FILE* out = fopen("data", "r");
if (out == NULL) {
fpiintf(stderr, "fopen error\n");
return ;
} if (fwrite(&blackbeard, sizeof(struct private), , out) == ) {
fprintf(stderr, "fwrite error\n");
return ;
} if (fclose(out)) {
fprintf(stderr, "fclose error\n");
return ;
} FILE* in = fopen("data", "r");
if (in == NULL) {
fprintf(stderr, "fopen error\n");
return ;
}
if (fread(&p, sizeof(struct private), , in) == ) {
fprintf(stderr, "fread error\n");
return ;
} if (fclose(in)) {
fprintf(stderr, "fclose error\n");
return ;
} fprintf(stdout, "name = \"%s\" booty = %lu beard_len = %u\n", p.name, p.booty, p.beard_len);
return ;
}
int fileno (FILE *stream); //返回文件流(C标准I/O库)对应的文件描述符(Unix系统调用)
3. 控制缓冲
4. 线程安全
void flockfile (FILE *stream);
void funlockfile (FILE *stream);
5.标准I/O的缺陷
reading data: kernel ==> standard I/O buffer ==> application buffer
writing data: application data ==> standard I/O buffer ==> kernel
Linux System Programming 学习笔记(三) 标准缓冲I/O的更多相关文章
- Linux System Programming 学习笔记(十一) 时间
1. 内核提供三种不同的方式来记录时间 Wall time (or real time):actual time and date in the real world Process time:the ...
- Linux System Programming 学习笔记(四) 高级I/O
1. Scatter/Gather I/O a single system call to read or write data between single data stream and mu ...
- Linux System Programming 学习笔记(二) 文件I/O
1.每个Linux进程都有一个最大打开文件数,默认情况下,最大值是1024 文件描述符不仅可以引用普通文件,也可以引用套接字socket,目录,管道(everything is a file) 默认情 ...
- Linux System Programming 学习笔记(十) 信号
1. 信号是软中断,提供处理异步事件的机制 异步事件可以是来源于系统外部(例如用户输入Ctrl-C)也可以来源于系统内(例如除0) 内核使用以下三种方法之一来处理信号: (1) 忽略该信号.SIG ...
- Linux System Programming 学习笔记(九) 内存管理
1. 进程地址空间 Linux中,进程并不是直接操作物理内存地址,而是每个进程关联一个虚拟地址空间 内存页是memory management unit (MMU) 可以管理的最小地址单元 机器的体系 ...
- Linux System Programming 学习笔记(七) 线程
1. Threading is the creation and management of multiple units of execution within a single process 二 ...
- Linux System Programming 学习笔记(六) 进程调度
1. 进程调度 the process scheduler is the component of a kernel that selects which process to run next. 进 ...
- Linux System Programming 学习笔记(一) 介绍
1. Linux系统编程的三大基石:系统调用.C语言库.C编译器 系统调用:内核向用户级程序提供服务的唯一接口.在i386中,用户级程序执行软件中断指令 INT n 之后切换至内核空间 用户程序通过寄 ...
- Linux System Programming 学习笔记(八) 文件和目录管理
1. 文件和元数据 每个文件都是通过inode引用,每个inode索引节点都具有文件系统中唯一的inode number 一个inode索引节点是存储在Linux文件系统的磁盘介质上的物理对象,也是L ...
随机推荐
- javaweb基础(1)_入门
一.基本概念 1.1.WEB开发的相关知识 WEB,在英语中web即表示网页的意思,它用于表示Internet主机上供外界访问的资源. Internet上供外界访问的Web资源分为: 静态web资源( ...
- echarts事件中获取当前实例
直接使用this即可
- 【转】本人常用资源整理(ing...)
Deep Learning(深度学习): ufldl的2个教程(这个没得说,入门绝对的好教程,Ng的,逻辑清晰有练习):一 ufldl的2个教程(这个没得说,入门绝对的好教程,Ng的,逻辑清晰有练习) ...
- 【主席树 启发式合并】bzoj3123: [Sdoi2013]森林
小细节磕磕碰碰浪费了半个多小时的时间 Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M ...
- JQuery图片轮播实例
HTML+CSS代码: <!doctype html> <html> <head> <meta charset="utf-8"> & ...
- Linux 命令、配置文件及操作
Linux 命令.配置文件及操作 命令 命令 参数 说明 A alias.unalias 命令别名 B C cat 查看文件内容 cd 切换目录 chown 修改拥有着 chgrp 修改所属组 chm ...
- Pycharm安装类库
比如安装requests 打开settings,选择Project 下面的Project Interpreter,点击pip,在弹出窗口里输入requests然后点击install 即可!
- 【android】【转发】Android中PX、DP、SP的区别
转载 http://blog.csdn.net/donkor_/article/details/77680042 前言: 众所周知,Android厂商非常多,各种尺寸的android手机.平板层出不穷 ...
- Python自定义一个数组类,支持数组之间的四则运算和其他常见方法
class MyArray: '''保证输入的内容是整型.浮点型''' def ___isNumber(self, num): if not isinstance(num, (int,float)): ...
- Python学习笔记:wxPython(GUI图形用户界面)
wxPython是一套基于Python的第三方GUI插件,可用Python制作丰富的图形化界面程序. 安装:pip install wxPython 或者 网站下载安装https://pypi.org ...