导语摘要 本书是被誉为UNIX编程“圣经”的Advanced Programming in the UNIX Environment一书的第3版。在本书第2版出版后的8年中,UNIX发生了巨大的变化,特别是影响UNIX编程接口的有关标准变化很大。本书在保持前一版风格的基础上,根据新的标准对内容进行了修订和增补,反映了新的技术发展。书中除了介绍UNIX文件和目录、标准I/O库、系统数据文件和信息、进程环境、进程控制、进程关系、信号、线程、线程控制、守护进程、各种I/O、进程间通信、网络IPC、伪终端等方面的内容,还在此基础上介绍了众多应用实例,包括如何创建数据库函数库以及如何与网络打印机通信等。此外,还在附录中给出了函数原型和部分习题的答案。 本书内容权威,概念清晰,阐述精辟,对于所有层次UNIX/Linux程序员都是一本不可或缺的参考书。
作者简介 W. 理查德·史蒂文斯(W. Richard Stevens),国际知名的UNIX 和网络专家,备受赞誉的技术作家。生前著有多部经典的传世之作,包括《UNIX 网络编程》(两卷本)、《TCP/IP 详解》(三卷本)和本书首版。 史蒂芬·A. 拉戈(Stephen A. Rago),资深UNIX 程序员,目前任NEC 美国实验室存储系统研究组研究员。之前是贝尔实验室的UNIX 系统V 版本4 的开发人员之一。著有《UNIX 系统V 网络编程》,是本书第1版的技术审校和第2 版的共同作者。
目录 目录
Chapter 1. UNIX System Overview / UNIX基础知识 1
1.1 Introduction / 引言 1
1.2 UNIX Architecture / UNIX体系结构 1
1.3 Logging In / 登录 2
1.4 Files and Directories / 文件和目录 4
1.5 Input and Output / 输入和输出 8
1.6 Programs and Processes / 程序和进程 10
1.7 Error Handling / 出错处理 14
1.8 User Identification / 用户标识 16
1.9 Signals / 信号 18
1.10 Time Values / 时间值 20
1.11 System Calls and Library Functions / 系统调用和库函数 21
1.12 Summary / 小结 23
Exercises / 习题 24
Chapter 2. UNIX Standardization and Implementations / UNIX标准及实现 25
2.1 Introduction / 引言 25
2.2 UNIX Standardization / UNIX标准化 25
2.2.1 ISO C 25
2.2.2 IEEE POSIX 26
2.2.3 The Single UNIX Specification 30
2.2.4 FIPS 32
2.3 UNIX System Implementations / UNIX系统实现 33
2.3.1 UNIX System V Release 4 / SVR4 33
2.3.2 4.4BSD 34
2.3.3 FreeBSD 34
2.3.4 Linux 35
2.3.5 Mac OS X 35
2.3.6 Solaris 35
2.3.7 Other UNIX Systems / 其他UNIX系统 35
2.4 Relationship of Standards and Implementations / 标准和实现的关系 36
2.5 Limits / 限制 36
2.5.1 ISO C Limits / ISO C限制 37
2.5.2 POSIX Limits / POSIX限制 38
2.5.3 XSI Limits / XSI限制 41
2.5.4 sysconf, pathconf, and fpathconf Functions / 函数sysconf、pathconf和fpathconf 42
2.5.5 Indeterminate Runtime Limits / 不确定的运行时限制 49
2.6 Options / 选项 53
2.7 Feature Test Macros / 功能测试宏 57
2.8 Primitive System Data Types / 基本系统数据类型 58
2.9 Differences Between Standards / 标准之间的冲突 58
2.10 Summary / 小结 60
Exercises / 习题 60
Chapter 3. File I/O / 文件I/O 61
3.1 Introduction / 引言 61
3.2 File Descriptors / 文件描述符 61
3.3 open and openat Functions / 函数open和openat 62
3.4 creat Function / 函数creat 66
3.5 close Function / 函数close 66
3.6 lseek Function / 函数lseek 66
3.7 read Function / 函数read 71
3.8 write Function / 函数write 72
3.9 I/O Efficiency / I/O的效率 72
3.10 File Sharing / 文件共享 74
3.11 Atomic Operations / 原子操作 77
3.12 dup and dup2 Functions / 函数dup和dup2 79
3.13 sync, fsync, and fdatasync Functions / 函数sync、fsync和fdatasync 81
3.14 fcntl Function / 函数fcntl 82
3.15 ioctl Function / 函数ioctl 87
3.16 /dev/fd 88
3.17 Summary / 小结 90
Exercises / 习题 90
Chapter 4. Files and Directories / 文件和目录 93
4.1 Introduction / 引言 93
4.2 stat, fstat, fstatat, and lstat Functions / 函数stat、fstat、fstatat和lstat 93
4.3 File Types / 文件类型 95
4.4 Set-User-ID and Set-Group-ID / 设置用户ID和设置组ID 98
4.5 File Access Permissions / 文件访问权限 99
4.6 Ownership of New Files and Directories / 新文件和目录的所有权 101
4.7 access and faccessat Functions / 函数access和faccessat 102
4.8 umask Function / 函数umask 104
4.9 chmod, fchmod, and fchmodat Functions / 函数chmod、fchmod和fchmodat 106
4.10 Sticky Bit / 粘着位 108
4.11 chown, fchown, fchownat, and lchown Functions / 函数chown、fchown、fchownat和lchown 109