●目錄Chapter 1. UNIX System Overview / UNIX基礎知識 11.1 Introduction / 引言 11.2 UNIX Architecture / UNIX體繫結構 11.3 Logging In / 登錄 21.4 Files and Directories / 文件和目錄 41.5 Input and Output / 輸入和輸出 81.6 Programs and Processes / 程序和進程 101.7 Error Handling / 出錯處理 141.8 User Identification / 用戶標識 161.9 Signals / 信號 181.10 Time Values / 時間值 201.11 System Calls and Library Functions / 繫統調用和庫函數 211.12 Summary / 小結 23Exercises / 習題 24Chapter 2. UNIX Standardization and Implementations / UNIX標準及實現 252.1 Introduction / 引言 252.2 UNIX Standardization / UNIX標準化 252.2.1 ISO C 252.2.2 IEEE IX 262.2.3 The Single UNIX Specification 302.2.4 FIPS 322.3 UNIX System Implementations / UNIX繫統實現 332.3.1 UNIX System V Release 4 / SVR4 332.3.2 4.4BSD 342.3.3 FreeBSD 342.3.4 Linux 352.3.5 Mac OS X 352.3.6 Solaris 352.3.7 Other UNIX Systems / 其他UNIX繫統 352.4 Relationship of Standards and Implementations / 標準和實現的關繫 362.5 Limits / 362.5.1 ISO C Limits / ISO C 372.5.2 IX Limits / IX 382.5.3 XSI Limits / XSI 412.5.4 sysconf, pathconf, and fpathconf Functions / 函數sysconf、pathconf和fpathconf 422.5.5 Indeterminate Runtime Limits / 不確定的運行時 492.6 Options / 選項 532.7 Feature Test Macros / 功能測試宏 572.8 Primitive System Data Types / 基本繫統數據類型 582.9 Differences Between Standards / 標準之間的衝突 582.10 Summary / 小結 60Exercises / 習題 60Chapter 3. File I/O / 文件I/O 613.1 Introduction / 引言 613.2 File Descriptors / 文件描述符 613.3 open and openat Functions / 函數open和openat 623.4 creat Function / 函數creat 663.5 close Function / 函數close 663.6 lseek Function / 函數lseek 663.7 read Function / 函數read 713.8 write Function / 函數write 723.9 I/O Efficiency / I/O的效率 723.10 File Sharing / 文件共享 743.11 Atomic Operations / 原子操作 773.12 dup and dup2 Functions / 函數dup和dup2 793.13 sync, fsync, and fdatasync Functions / 函數sync、fsync和fdatasync 813.14 fcntl Function / 函數fcntl 823.15 ioctl Function / 函數ioctl 873.16 /dev/fd 883.17 Summary / 小結 90Exercises / 習題 90Chapter 4. Files and Directories / 文件和目錄 934.1 Introduction / 引言 934.2 stat, fstat, fstatat, and lstat Functions / 函數stat、fstat、fstatat和lstat 934.3 File Types / 文件類型 954.4 Set-User-ID and Set-Group-ID / 設置用戶ID和設置組ID 984.5 File Access Permissions / 文件訪問權限 994.6 Ownership of New Files and Directories / 新文件和目錄的所有權 1014.7 access and faccessat Functions / 函數access和faccessat 1024.8 umask Function / 函數umask 1044.9 chmod, fchmod, and fchmodat Functions / 函數chmod、fchmod和fchmodat 1064.10 Sticky Bit / 粘著位 1084.11 chown, fchown, fchownat, and lchown Functions / 函數chown、fchown、fchownat和lchown 1094.12 File Size / 文件長度 1114.13 File Truncation / 文件截斷 1124.14 File Systems / 文件繫統 1134.15 link, linkat, unlink, unlinkat, and remove Functions / 函數link、linkat、unlink、unlinkat和remove 1164.16 rename and renameat Functions / 函數rename和renameat 1194.17 Symbolic Links / 符號鏈接 1204.18 Creating and Reading Symbolic Links / 創建和讀取符號鏈接 1234.19 File Times / 文件的時間 1244.20 futimens, utimensat, and utimes Functions / 函數futimens、utimensat和utimes 1264.21 mkdir, mkdirat, and rmdir Functions / 函數mkdir、mkdirat和rmdir 1294.22 Reading Directories / 讀目錄 1304.23 chdir, fchdir, and getcwd Functions / 函數chdir、fchdir和getcwd 1354.24 Device Special Files / 設備特殊文件 1374.25 Summary of File Access Permission Bits / 文件訪問權限位小結 1404.26 Summary / 小結 140Exercises / 習題 141Chapter 5. Standard I/O Library / 標準I/O庫 1435.1 Introduction / 引言 1435.2 Streams and FILE Objects / 流和FILE對像 1435.3 Standard Input, Standard Output, and Standard Error / 標準輸入、標準輸出和標準錯誤 1455.4 Buffering / 緩衝 1455.5 Opening a Stream / 打開流 1485.6 Reading and Writing a Stream / 讀和寫流 1505.7 Line-at-a-Time I/O / 每次一行I/O 1525.8 Standard I/O Efficiency / 標準I/O的效率 1535.9 Binary I/O / 二進制I/O 1565.10 itioning a Stream / 定位流 1575.11 Formatted I/O / 格式化I/O 1595.12 Implementation Details / 實現細節 1645.13 Temporary Files / 臨時文件 1675.14 Memory Streams / 內存流 1715.15 Alternatives to Standard I/O / 標準I/O的替代軟件 1745.16 Summary / 小結 175Exercises / 習題 175Chapter 6. System Data Files and Information / 繫統數據文件和信息 1776.1 Introduction / 引言 1776.2 Password File / 口令文件 1776.3 Shadow Passwords / 陰影口令 1816.4 Group File / 組文件 1826.5 Supplementary Group IDs / 附屬組ID 1836.6 Implementation Differences / 實現區別 1846.7 Other Data Files / 其他數據文件 1856.8 Login Accounting / 登錄賬戶記錄 1866.9 System Identification / 繫統標識 1876.10 Time and Date Routines / 時間和日期例程 1896.11 Summary / 小結 196Exercises / 習題 196Chapter 7. Process Environment / 進程環境 1977.1 Introduction / 引言 1977.2 main Function / main函數 1977.3 Process Termination / 進程終止 1987.4 Command-Line Arguments / 命令行參數 2037.5 Environment List / 環境表 2037.6 Memory Layout of a C Program / C程序的存儲空間布局 2047.7 Shared Libraries / 共享庫 2067.8 Memory Allocation / 存儲空間分配 2077.9 Environment Variables / 環境變量 2107.10 setjmp and longjmp Functions / 函數setjmp和longjmp 2137.11 getrlimit and setrlimit Functions / 函數getrlimit和setrlimit 2207.12 Summary / 小結 225Exercises / 習題 226Chapter 8. Process Control / 進程控制 2278.1 Introduction / 引言 2278.2 Process Identifiers / 進程標識 2278.3 fork Function / 函數fork 2298.4 vfork Function / 函數vfork 2348.5 exit Functions / 函數exit 2368.6 wait and waitpid Functions / 函數wait和waitpid 2388.7 waitid Function / 函數waitid 2448.8 wait3 and wait4 Functions / 函數wait3和wait4 2458.9 Race Conditions / 競爭條件 2458.10 exec Functions / 函數exec 2498.11 Changing User IDs and Group IDs / 更改用戶ID和更改組ID 2558.12 Interpreter Files / 解釋器文件 2608.13 system Function / 函數system 2648.14 Process Accounting / 進程會計 2698.15 User Identification / 用戶標識 2758.16 Process Scheduling / 進程調度 2768.17 Process Times / 進程時間 2808.18 Summary / 小結 282Exercises / 習題 283Chapter 9. Process Relationships / 進程關繫 2859.1 Introduction / 引言 2859.2 Terminal Logins / 終端登錄 2859.3 Network Logins / 網絡登錄 2909.4 Process Groups / 進程組 2939.5 Sessions / 會話 2959.6 Controlling Terminal / 控制終端 2969.7 tcgetpgrp, tcsetpgrp, and tcgetsid Functions / 函數tcgetpgrp、tcsetpgrp和tcgetsid 2989.8 Job Control / 作業控制 2999.9 Shell Execution of Programs / Shell執行程序 3039.10 Orphaned Process Groups / 孤兒進程組 3079.11 FreeBSD Implementation / FreeBSD實現 3109.12 Summary / 小結 312Exercises / 習題 312Chapter 10. Signals / 信號 31310.1 Introduction / 引言 31310.2 Signal Concepts / 信號概念 31310.3 signal Function / 函數signal 32310.4 Unreliable Signals / 不可靠的信號 32610.5 Interrupted System Calls / 中斷的繫統調用 32710.6 Reentrant Functions / 可重入函數 33010.7 SIGCLD Semantics / SIGCLD語義 33210.8 Reliable-Signal Terminology and Semantics / 可靠信號術語和語義 33510.9 kill and raise Functions / 函數kill和raise 33610.10 alarm and pause Functions / 函數alarm和pause 33810.11 Signal Sets / 信號集 34410.12 sigprocmask Function / 函數sigprocmask 34610.13 sigpending Function / 函數sigpending 34710.14 sigaction Function / 函數sigaction 34910.15 sigsetjmp and siglongjmp Functions / 函數sigsetjmp和siglongjmp 35510.16 sigsuspend Function / 函數sigsuspend 35910.17 abort Function / 函數abort 36510.18 system Function / 函數system 36710.19 sleep, nanosleep, and clock_nanosleep Functions / 函數sleep、nanosleep和clock_nanosleep 37310.20 sigqueue Function / 函數sigqueue 37610.21 Job-Control Signals / 作業控制信號 37710.22 Signal Names and Numbers / 信號名和編號 37910.23 Summary / 小結 381Exercises / 習題 381Chapter 11. Threads / 線程 38311.1 Introduction / 引言 38311.2 Thread Concepts / 線程概念 38311.3 Thread Identification / 線程標識 38411.4 Thread Creation / 線程創建 38511.5 Thread Termination / 線程終止 38811.6 Thread Synchronization / 線程同步 39711.6.1 texes / 互斥量 39911.6.2 Deadlock Avoidance / 避免死鎖 40211.6.3 pthread_mutex_timedlock Function / 函數pthread_mutex_timedlock 40711.6.4 Reader-Writer Locks / 讀寫鎖 40911.6.5 Reader-Writer Locking with Timeouts / 帶有超時的讀寫鎖 41311.6.6 Condition Variables / 條件變量 41311.6.7 Spin Locks / 自旋鎖 41711.6.8 Barriers / 屏障 41811.7 Summary / 小結 422Exercises / 習題 422Chapter 12. Thread Control / 線程控制 42512.1 Introduction / 引言 42512.2 Thread Limits / 線程 42512.3 Thread Attributes / 線程屬性 42612.4 Synchronization Attributes / 同步屬性 43012.4.1 tex Attributes / 互斥量屬性 43012.4.2 Reader-Writer Lock Attributes / 讀寫鎖屬性 43912.4.3 Condition Variable Attributes / 條件變量屬性 44012.4.4 Barrier Attributes / 屏障屬性 44112.5 Reentrancy / 重入 44212.6 Thread-Specific Data / 線程特定數據 44612.7 Cancel Options / 取消選項 45112.8 Threads and Signals / 線程和信號 45312.9 Threads and fork / 線程和fork 45712.10 Threads and I/O / 線程和I/O 46112.11 Summary / 小結 462Exercises / 習題 462Chapter 13. Daemon Processes / 守護進程 46313.1 Introduction / 引言 46313.2 Daemon Characteristics / 守護進程的特征 46313.3 Coding Rules / 編程規則 46613.4 Error Logging / 出錯記錄 46913.5 Single-Instance Daemons / 單實例守護進程 47313.6 Daemon Conventions / 守護進程的慣例 47413.7 Client-Server Model / 客戶進程-服務器進程模型 47913.8 Summary / 小結 480Exercises / 習題 480Chapter 14. Advanced I/O / 高級I/O 48114.1 Introduction / 引言 48114.2 Nonblocking I/O / 非阻塞I/O 48114.3 Record Locking / 記錄鎖 48514.4 I/O ltiplexing / I/O多路轉接 50014.4.1 select and pselect Functions / 函數select和pselect 50214.4.2 poll Function / 函數poll 50614.5 Asynchronous I/O / 異步I/O 50914.5.1 System V Asynchronous I/O / System V異步I/O 51014.5.2 BSD Asynchronous I/O / BSD異步I/O 51014.5.3 IX Asynchronous I/O / IX異步I/O 51114.6 readv and writev Functions / 函數readv和writev 52114.7 readn and writen Functions / 函數readn和writen 52314.8 Memory-Mapped I/O / 存儲映射I/O 52514.9 Summary / 小結 531Exercises / 習題 532Chapter 15. Interprocess Communication / 進程間通信 53315.1 Introduction / 引言 53315.2 Pipes / 管道 53415.3 popen and pclose Functions / 函數popen和pclose 54115.4 Coprocesses / 協同進程 54815.5 FIFOs 55215.6 XSI IPC 55615.6.1 Identifiers and Keys / 標識符和鍵 55615.6.2 Permission Structure / 權限結構 55815.6.3 Configuration Limits / 結構 55915.6.4 Advantages and Disadvantages / 優點和缺點 55915.7 Message Queues / 消息隊列 56115.8 Semaphores / 信號量 56515.9 Shared Memory / 共享存儲 57115.10 IX Semaphores / IX信號量 57915.11 Client-Server Properties / 客戶進程-服務器進程屬性 58515.12 Summary / 小結 587Exercises / 習題 587Chapter 16. Network IPC: Sockets / 網絡IPC:套接字 58916.1 Introduction / 引言 58916.2 Socket Descriptors / 套接字描述符 59016.3 Addressing / 尋址 59316.3.1 Byte Ordering / 字節序 59316.3.2 Address Formats / 地址格式 59516.3.3 Address Lookup / 地址查詢 59716.3.4 Associating Addresses with Sockets / 將套接字與地址關聯 60416.4 Connection Establishment / 建立連接 60516.5 Data Transfer / 數據傳輸 61016.6 Socket Options / 套接字選項 62316.7 Out-of-Band Data / 帶外數據 62616.8 Nonblocking and Asynchronous I/O / 非阻塞和異步I/O 62716.9 Summary / 小結 628Exercises / 習題 628Chapter 17. Advanced IPC / 高級進程間通信 62917.1 Introduction / 引言 62917.2 UNIX Domain Sockets / UNIX域套接字 62917.3 Unique Connections / 專享連接 63517.4 Passing File Descriptors / 傳送文件描述符 64217.5 An Open Server, Version 1 / 打開服務器進程第 1版 65317.6 An Open Server, Version 2 / 打開服務器進程第 2版 65917.7 Summary / 小結 669Exercises / 習題 670Chapter 18. Terminal I/O / 終端I/O 67118.1 Introduction / 引言 67118.2 Overview / 概述 67118.3 Special Input Characters / 特殊輸入字符 67818.4 Getting and Setting Terminal Attributes / 獲得和設置終端屬性 68318.5 Terminal Option Flags / 終端選項標志 68318.6 stty Command / stty命令 69118.7 Baud Rate Functions / 波特率函數 69218.8 Line Control Functions / 行控制函數 69318.9 Terminal Identification / 終端標識 69418.10 Canonical Mode / 規範模式 70018.11 Noncanonical Mode / 非規範模式 70318.12 Terminal Window Size / 終端窗口大小 71018.13 termcap, terminfo, and curses / termcap、terminfo和curses 71218.14 Summary / 小結 713Exercises / 習題 713Chapter 19. Pseudo Terminals / 偽終端 71519.1 Introduction / 引言 71519.2 Overview / 概述 71519.3 Opening Pseudo-Terminal Devices / 打開偽終端設備 72219.4 pty_fork Function / 函數pty_fork 72619.5 pty Program / pty程序 72919.6 Using the pty Program / 使用pty程序 73319.7 Advanced Features / 高級特性 74019.8 Summary / 小結 741Exercises / 習題 742Chapter 20. A Database Library / 數據庫函數庫 74320.1 Introduction / 引言 74320.2 History / 歷史 74320.3 The Library / 函數庫 74420.4 Implementation Overview / 實現概述 74620.5 Centralized or Decentralized / 集中式還是非集中式 75020.6 Concurrency / 並發 75220.7 Building the Library / 構造函數庫 75320.8 Source Code / 源代碼 75320.9 Performance / 性能 78120.10 Summary / 小結 786Exercises / 習題 787Chapter 21. Communicating with a Network Printer / 與網絡打印機通信 78921.1 Introduction / 引言 78921.2 The Internet Printing Protocol / 網絡打印協議 78921.3 The Hypertext Transfer Protocol / 超文本傳輸協議HTTP 79221.4 Printer Spooling / 打印假脫機技術 79321.5 Source Code / 源代碼 79521.6 Summary / 小結 843Exercises / 習題 843Appendix A. Function Prototypes / 函數原型 845Appendix B. Miscellaneous Source Code / 其他源代碼 895B.1 Our Header File / 本書使用的頭文件 895B.2 Standard Error Routines / 標準出錯例程 898Appendix C. Solutions to Selected Exercises / 部分習題答案 905Bibliography / 參考書目 947
本書是被譽為UNIX編程“”的Advanced Programming in the UNIX Environment一書的第3版。在本書第2版出版後的8年中,UNIX發生了巨大的變化,特別是影響UNIX編程接口的有關標準變化很大。本書在保持前一版風格的基礎上,根據新的標準對內容進行了修訂和增補,反映了新的技術發展。書中除了介紹UNIX文件和目錄、標準I/O庫、繫統數據文件和信息、進程環境、進程控制、進程關繫、信號、線程、線程控制、守護進程、各種I/O、進程間通信、網絡IPC、偽終端等方面的內容,還在此基礎上介紹了眾多應用實例,包括如何創建數據庫函數庫以及如何與網絡打印機通信等。此外,還在附錄中給出了函數原型和部分習題的答案。本書內容權威,概念清晰,闡述精闢,對於所有層次UNIX/Linux程序員都是一本不可或缺的參考書。