美文网首页
2019-10-18

2019-10-18

作者: 星球发动机 | 来源:发表于2019-10-18 21:44 被阅读0次

第三章 文件IO

3.1 引言

unix大多数文件的IO只需要用到5个函数:open read write lseek close

不同的缓冲长度,对read 和 write 函数 有影响

3.2 文件描述符

对于内核而言,所有打开的文件,都通过文件描述符引用、文件描述符是一个非负整数、

当打开一个文件。或者创建一个新文件,内核向进程返回一个文件描述符。打开文件是一个进程。

当使用open creat 返回一个文件描述符标识一个文件,并将其作为参数传递给read和write。

文件描述符 0与标准输入关联,文件描述符1与标准输出关联,文件描述符2与标准错误关联。

幻数  0,1,2已经在POSIX.1标准化,我们使用

STDIN_FILENO STDOUT_FILENO 和STDERR_FILENO 作为标准IO的,这几个常量在

<unistd.h>中定义

文件描述符 范围 是 

第4章:Unix文件和目录

本章描述文件系统的其他属性和文件的性质。

4.2 函数stat fstat fstatat lstat

#include <sys/stat.h>

int stat(const char *restrict pathname, struct stat *restrict buf);

int fstat(int fd, struct stat *buf);

int lstat(const char *restrict pathname, struct stat *restrict buf)

int fstatat(int fd, const char *restrict pathname, struct stat *restrict buf, int fd)

这4个函数的返回值,若成功则返回0;若出错返回-1

相关文章

  • ES 故障

    2019-10-18 primary shard lost unassigned_info "can_alloca...

  • B Tree

    2019-10-18 https://leetcode-cn.com/tag/dynamic-programmin...

  • ES uasge

    2019-10-18 nested https://blog.csdn.net/laoyang360/articl...

  • Druid share

    2019-10-18 Druid share overloadtask dispatch/assign只在启动时l...

  • note

    2019-10-18 NLP 提升树 xgboot lightgbm sklearn->gbdt 添加正则 防止过...

  • 10月18日

    2019-10-18 毛雅亭 字数 484 · 阅读 14 2019-09-25 08:27 ...

  • 2019-10-21

    10.18 幸幸_b606 0.096 · 字数 77 · 阅读 10 2019-10-18 08:19 5:00...

  • 2019-10-20

    2019-10-18 朋友 我们认识许多人,有的点头之交,有的偶尔联系,有的常常见...

  • 和舒服的人在一起,就是最好的养生

    媒体:方圆杂志 2019-10-18 12:01 点击查看短片:恋人必看的温情爱情短片《love is》 找个相处...

  • Snail的ScalersTalk第五轮新概念朗读持续力训练Da

    • 标题: Snail的ScalersTalk第五轮新概念朗读持续力训练Day8 2019-10-18 • 正文...

网友评论

      本文标题:2019-10-18

      本文链接:https://www.haomeiwen.com/subject/pnvwmctx.html