编程实践手册1 - DDL-Killer/The-road-of-Linxu-Group2024 GitHub Wiki

三个基本系统函数

open()

  • 基本用法
    图片

read()

  • 基本用法 图片

close()

  • 基本用法
    图片

编写cp

cp命令能做些什么?

  • cp能够复制文件

cp命令是如何创建/重写文件的

  1. 创建/重写文件
    使用creat函数
    图片

  2. 写文件
    用write函数 图片

  3. 如何编写cp

    1. open sourcefile for reading
    2. open copyfile for writing
    3. read from source to buffer
    4. write from buffer to copy
    5. close sourcefile
    6. close copyfile

提高文件I/O效率的方法:使用缓冲

系统调用需要时间的原因

  • 磁盘只能被内核直接访问,执行内核代码是需要时间的

在who2.c中运用缓冲技术

  • 用一个能容纳16个utmp结构的数组作为缓冲区,编写utmp_next函数来从缓冲区中获得下一个utmp结构的数据