5 F I L E I / O : F U R T H E R D E T A I L S

本文深入探讨了系统调用中的原子性概念,如open()的O_EXCL和O_APPEND标志,以及fcntl()、dup()、pread()、pwrite()等系统调用的功能。介绍了文件描述符、open文件描述和文件i-nodes之间的关系,并讨论了非阻塞I/O、LFS规格、/dev/fd目录和创建临时文件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Summary
In the course of this chapter, we introduced the concept of atomicity, which is crucial to the correct operation of some system calls. In particular, the open() O_EXCL flag allows the caller to ensure that it is the creator of a file, and the open() O_APPEND flag ensures that multiple processes appending data to the same file don’t overwrite each other’s output.

The fcntl() system call performs a variety of file control operations, including changing open file status flags and duplicating file descriptors.

Duplicating file descriptors is also possible using dup() and dup2().

We looked at the relationship between file descriptors, open file descriptions, and file i-nodes, and noted that different information is associated with each of these three objects.

Duplicate file descriptors refer to the same open file description, and thus share open file status flags and the file offset.

We described a number of system calls that extend the functionality of the conventional read() and write() system calls.

The pread() and pwrite() system calls perform I/O at a specified file location without changing the file offset.

The readv() and writev() calls perform scatter-gather I/O.

The preadv() and pwritev() calls combine scatter-gather I/O functionality with the ability to perform I/O at a specified file
location.

The truncate() and ftruncate() system calls can be used to decrease the size of a file, discarding the excess bytes, or to increase the size, padding with a zero-filled file hole.

We briefly introduced the concept of nonblocking I/O, and we’ll return to it in later chapters.

The LFS specification defines a set of extensions that allow processes running on 32-bit systems to perform operations on files whose size is too large to be represented in 32 bits.

The numbered files in the /dev/fd virtual directory allow a process to access its own open files via file descriptor numbers, which can be particularly useful in shell commands.

The mkstemp() and tmpfile() functions allow an application to create temporary files.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值