If you are an experienced C programmer with a working knowledge of UNIX, you cannot afford to be without this up-to -date tutorial on the system call interface and the most important functions found in the ANSI C library. Richard Stevens describes more than 200 system calls and functions; since he believes the best way to learn code is to read code,a brief example accompanies each description. Building upon information presented in the first 15 chapters, the author offers chapter-long examples teaching you how to create a database library, a PostScript printer driver, a modem dialer, and a program that runs other programs under a pseudo terminal. To make your analysis and understanding ofthis code even easier, and to allow you to modify it, all of the code in the book is available via UUNET. Advanced Programming in the UNIX Environment is applicable to all major UNIX releases, especially System V Release $ and the latest release of 4.3BSD, including 386BSD. These real-world implementations allow you to more clearly understand the status of the current and future standards,including IEEE POSIX and XPG3.
\r\n
Preface\r\n\r\nChapter 1.Introduction\r\n\r\n1.1 Introduction\r\n1.2 Logging In\r\n1.3 Files and Directories\r\n1.4 Input and Output\r\n1.5 Programs and Processes\r\n1.6 ANSI C Features\r\n1.7 Error Handling\r\n1.8 User Identification\r\n1.9 Signals\r\n1.10 Unix Time Values\r\n1.11 System Calls and Library Functions\r\n1.12 Summary\r\n\r\nChapter 2. Unix Standardization and Implementations\r\n\r\n2.1 Introduction\r\n2.2 Unix Standardization\r\n2.3 Unix Implementations\r\n2.4 Relationship of Standards and Implementations\r\n2.5 Limits\r\n2.6 Feature Test Macros\r\n2.7 Primitive System Data Types\r\n2.8 Conflicts Between Standards\r\n2.9 Summary\r\n\r\nChapter 3. FiIe I/O\r\n\r\n3.1 Introduction\r\n3.2 File Descriptors\r\n3.3 open Function\r\n3.4 creat Function\r\n3.5 close Function\r\n3.6 lseek Function\r\n3.7 read Function\r\n3.8 write Function\r\n3.9 I/O Efficiency\r\n3.10 File Sharing\r\n3.11 Atomic Operations\r\n3.12 dup and dup2 Functions\r\n3.13 fcntl Function\r\n3.14 ioctl Function\r\n3.15 /dev/fd\r\n3.16 Summary\r\n\r\nChapter 4. Files and Directories\r\n\r\n4.1 Introduction\r\n4.2 stat, fstat, and lstat Functions\r\n4.3 File Types\r\n4.4 Set-User-ID and Set-Group-lD\r\n4.5 File Access Permissions\r\n4.6 Ownership of New Files and Directories\r\n4.7 access Function\r\n4.8 umask Function\r\n4.9 chmod and fchmod Functions\r\n4.10 Sticky Bit 88\r\n4.11 chown, fchown, and lchown Functions\r\n4.12 File Size\r\n4.13 File Truncation\r\n4.14 Fijesystems\r\n4.15 link, unlink, remove, and rename Functions\r\n4.16 Symbolic Links\r\n4.17 symlink and readlink Functions\r\n4.18 File Times\r\n4.19 utime Function\r\n4.20 mkdir and rmdir Functions\r\n4.21 Reading Directories\r\n4.22 chdir, fchdir, and getcwd Functions\r\n4.23 Special Device Files\r\n4.24 sync and fsync Functions\r\n4.25 Summary of File Access Permission Bits\r\n4.26 Summary\r\n\r\nChapter 5. Standard I/O Library\r\n\r\n5.1 Introduction\r\n5.2 Streams and FILE Objects\r\n5.3 Standard Input, Standard Output, and Standard Error\r\n5.4 Buffering\r\n5.5 Opening a Stream\r\n5.6 Reading and Writing a Stream\r\n5.7 Line-at-a-Time I/O\r\n5.8 Standard I/O Efficiency\r\n5.9 Binary I/O\r\n5.10 Posltioning a Stream\r\n5.11 Formatted I/O\r\n5.12 Implementation Details\r\n5.13 Temporary Files\r\n5.14 Alternatives to Standard I/O\r\n5.15 Summary\r\n\r\nChapter 6. System Data Files and Information\r\n\r\n6.1 Introduction\r\n6.2 Password File\r\n6.3 Shadow Passwords\r\n6.4 Group File\r\n6.5 Supplementary Group IDs\r\n6.6 Other Data Files\r\n6.7 Login Accounting\r\n6.8 System Identification\r\n6.9 Time and Date Routines\r\n6.10 Summary\r\n\r\nChapter 7. The Environment of a Unix Process\r\n\r\n7.1 Introduction\r\n7.2 main Function\r\n7.3 Process Termination\r\n7.4 Command-Line Arguments\r\n7.5 Environment List\r\n7.6 Memory Layout of a C Program\r\n7.7 Shared Libraries\r\n7.8 Memory Allocation\r\n7.9 Environment Variables\r\n7.10 set jmp and ionqjmp Functions\r\n7.11 qetrlimit and setrlimit Functions\r\n7.12 Summary\r\n\r\nChapter 8. Process Control\r\n\r\n8.1 Introduction\r\n8.2 Process Identifiers\r\n8.3 fork Function\r\n8.4 vfork Function\r\n8.5 exit Functions\r\n8.6 wait and waitpid Functions\r\n8.7 wait3 and wait4 Functions\r\n8.8 Race Conditions\r\n8.9 exec Functions\r\n8.10 Changing User IDs and Group IDs\r\n8.11 Interpreter Files\r\n8.12 system Function\r\n8.13 Process Accounting\r\n8.14 User Identification\r\n8.15 Process Times\r\n8.16 Summary\r\n\r\nChapter 9. Process Relationships\r\n\r\n9.1 Introduction\r\n9.2 Terminal Logins\r\n9.3 Network Logins\r\n9.4 Process Groups\r\n9.5 Sessions\r\n9.6 Controlling Terminal\r\n9.7 tcgetpqrp and tcsetpgrp Functions\r\n9.8 Job Control\r\n9.9 Shell Execution of Programs\r\n9.10 Orphaned Process Groups\r\n9.11 4.3+BSD Implementation\r\n9.12 Summary\r\n\r\nChapter 10. Signals\r\n\r\n10.1 Introduction\r\n10.2 Signal Concepts\r\n10.3 signal Function\r\n10.4 Unreliable Signals\r\n10.5 Interrupted System Calls\r\n10.6 Reentrant Functions\r\n10.7 SIGCLD Semantics\r\n10.8 Reliable Signal Terminology and Semantics\r\n10.9 kill and ra1se Functions\r\n10.10 alarm and pause Functions\r\n10.11 Signal Sets\r\n10.12 siqprocmask Function\r\n10.13 siqpending Function\r\n10.14 sigaction Function\r\n10.15 sigsetjmp and siglongjmp Functions\r\n10.16 siqsuspend Function\r\n10.17 abort Function\r\n10.18 system Function\r\n10.19 sleep Function\r\n10.20 Job-Control Signals\r\n10.21 Addltional Features\r\n10.22 Summary\r\n\r\nChapter 11. Terminal I/O\r\n\r\n11.1 Introduction\r\n11.2 Overview\r\n11.3 Special Input Characters\r\n11.4 Getting and Setting Terminal Attributes\r\n11.5 Terminal Option Flags\r\n11.6 stty Command\r\n11.7 Baud Rate Functions\r\n11.8 Line Control Functions\r\n11.9 Terminal Identification\r\n11.10 Canonical Mode\r\n11.11 Noncanonical Mode\r\n11.12 Terminal Window Size\r\n11.13 termcap, terminfo. and curses\r\n11.14 Summary\r\n\r\nChapter 12. Advanced I/O\r\n\r\n12.1 Introduction\r\n12.2 Nonblocking I/O\r\n12.3 Record Locking\r\n12.4 Streams\r\n12 5 I/O Multiplexing\r\n12.6 Asynchronous I/O\r\n12.7 readv and writev Functions\r\n12.8 readn and writen Functions\r\n12.9 Memory Mapped I/O\r\n12.10 Summary\r\n\r\nChapter 13. Daemon Processes\r\n\r\n13.1 Introduction\r\n13.2 Daemon Characteristics\r\n13.3 Coding Rules\r\n13.4 Error Loggjng\r\n13.5 Client-Server Model\r\n13.6 Summary\r\n\r\nChapter 14. Interprocess Communication\r\n\r\n14.1 Introduction\r\n14.2 Pipes\r\n14.3 popen and pciose Functions\r\n14.4 Coprocesses\r\n14.5 FIFOs\r\n14.6 System V IPC\r\n14.7 Message Queues\r\n14.8 Semaphores\r\n14.9 Shared Memory\r\n14.10 Client-Server Properties\r\n14.11 Summary\r\n\r\nChapter 15. Advanced Interprocess Communication\r\n\r\n15.1 Introduction\r\n15.2 Stream Pipes\r\n15.3 Passing File Descriptors\r\n15.4 An Open Server, Version 1\r\n15.5 Client--Server Connection Functions\r\n15.6 An Open Server, Version 2\r\n15.7 Summary\r\n\r\nChapter 16. A Database Library\r\n\r\n16.1 Introduction\r\n16.2 History\r\n16.3 The Library\r\n16.4 Implementation Overview\r\n16.5 Centralized or Decentralized?\r\n16.6 Concurrency\r\n16.7 Source Code\r\n16.8 Performance\r\n16.9 Summary\r\n\r\nChapter 17. Communicating with a PostScript Printer\r\n\r\n17.1 Introduction\r\n17.2 PostScript Communication Dynamics\r\n17.3 Printer Spooling\r\n17.4 Source Code\r\n17.5 Summary\r\n\r\nChapter 18. A Modem Dialer\r\n\r\n18.1 Introduction\r\n18.2 History\r\n18.3 Program Design\r\n18.4 Data Files\r\n18.5 Server Design\r\n18.6 Server Source Code\r\n18.7 Client Design\r\n18.8 Client Source Code\r\n18.9 Summary\r\n\r\nChapter 19. Pseudo Terminals\r\n\r\n19.1 Introduction\r\n19.2 Overview\r\n19.3 Opening Pseudo-Terminal Devices\r\n19.4 pty_fork Function\r\n19.5 pty Program\r\n19.6 Using the pty Program\r\n19.7 Advanced Features\r\n19.8 Summary\r\n\r\nAppendix A. Function Prototypes\r\n\r\nAppendix B. Miscellaneous Source Code\r\n\r\nB.1 Our Header File\r\nB.2 Standard Error Routines\r\n\r\nAppendix C. Solutions to Selected Exercises\r\n\r\nBibliography\r\n\r\nIndex