Review: Advanced Programming in the Unix Environment
Advanced Programming in the UNIX® Environment | |
author | W. Richard Stevens |
pages | |
publisher | Addison Wesley Publishing Company, Inc. |
rating | 10/10 |
reviewer | Arjen Laarhoven |
ISBN | 0-201-56317-7 |
summary |
If you want to learn how to make (systems) programs in Unix, this book is invaluable. Whether you are an experienced professional programmer coming from another environment such as Windows or Mac, or a college student who wants to make programs that run on Linux, *BSD and/or workstations at school, this book is for you, and is an excellent step in the direction of Unix guru-hood.
Today, things like graphics, object-oriented programming, Java, Perl and component-ware are highly valued, and sometimes with good reason. But more and more an important aspect of programming is neglected: systems programming. Getting as close to the underlying system as possible. I think that it is important for anyone interested in programming on a particular platform (and not only the Unix platform) to get at least a "nodding acquaintance" with the API of that underlying system. It gives you a valuable insight in how things are done, and enables you to make more intelligent design and implementation decisions in programming on a higher level. Also, it is real fun (IMHO) to really get down to the system (but this is not news to Linux hackers :-).
Advanced Programming in the UNIX® Environment (APUE) is a book that shows how to get close to the Unix system, while remaining portable across the different flavors of Unix. It does this with remarkable clarity. Anyone who knows books written by Stevens knows what I'm talking about. All his books are of very high quality. I own them all, except the first edition of UNIX Network Programming.
APUE is somewhat structured like a textbook on operating systems, unsurprisingly. It begins with an overview introduction of Unix, explaining some important basic concepts, and the standardization of Unix. See the table of contents at the end of this review.
There are three chapters with complete example applications, in which practically all the material in the preceding chapters is used in a real-world setting. These examples are completely worked out, explaining how and why certain things are done as they are.
The most striking thing about this book that it really explains the system calls and their relationships with other parts of the system, rather than just summing up system calls and leaving you in the dark about how, why and where to use them. Also, there are a lot of tables, diagrams and shell interaction transcripts that summarize and visualize the workings of the system calls and the programs that use them.
Although you can learn much by just reading, you really gain an understanding by really working with the material presented. A lot of complete code examples are given throughout the book, and Stevens invites, no urges you to compile, run and tinker with it. All the examples are available in a package which can be downloaded from Stevens' home page, ready to compile, run and modify.
What's in it for me?
You can learn how to program in Unix by studying the manual pages and reading other people's code (which you should :-), but this book makes the learning curve much more smooth by providing an overview of the concepts and the relationships between them, before diving deep into the details.An important aspect of Unix programming is portability. APUE contains many pointers on writing programs that are portable across different Unix systems, taking the SysV and BSD differences as a starting point. Also, APUE discusses standards as POSIX.1, XPG3 (now XPG4) and explains the differences between them where appropriate. The code examples are in ANSI (ISO) C. An important part of C is the Standard I/O Library, and APUE provides a whole chapter on this, comparing the Standard I/O Library with the low-level file I/O systems calls, and the relationship between them.
The most important feature of this book (IMHO) are the exercises at the end of each chapter. These provide valuable additional insight in the material discussed by forcing you to think about the stuff you read. To make this book suitable for self-study, all exercises, except the "programming assignments", have answers in an appendix, so you can check your answers.
What's Good?
Well, practically all of it. Most importantly, the clarity and depth of the text. The diagrams are excellent and do not have unnecessary graphical frills that make them hard to understand. The exercises with answers help you to get a deeper understanding of the material presented, by letting you think about it. Some exercises are easy, but some of them are non-trivial and require creativity to solve. All the code examples are working programs, not just snippets that you have to cast into something working.Besides being an excellent textbook on Unix programming, it is also a very good reference manual. APUE is logically structured, and all the system calls are easily found, by means of boxes around them. An appendix contains an alphabetically sorted list of all the system calls discussed, with the possible return values and constants associated with them.
What's bad?
Not much. There are some things that you could complain about, but I think these have mainly to do with the age of the book (it's 6 years old now), rather than lack of quality. The most important thing is that the references to the standards are a little outdated. POSIX is more mature now, and the XPG3 standard is replaced by XPG4. I do not have access to these standards, but I don't think that there are any revolutionary changes. Also, APUE talks about BSD 4.3, while 4.4 is available for quite some time now. Linux is not mentioned at all, but that is no surprise. All the material, however, is perfectly valid for Linux programming (and Stevens' newer books do refer to our favorite operating system).Other things you can complain about are 1) it does not have any networking stuff in it, and 2) that threads (which are becoming more and more popular tool) are not discussed. For networking, I think that networking simply falls outside the scope of this book. Unix is used mainly in networked environments (and is the superior system in that environment), but it is really an extension of the capabilities of Unix, rather than a low-level integral part.
For the threads case, you have to know that this book is already 6 years old (and is still very useful, because the basic structure of Unix does not really change), and thread programming was not such a big issue in 1992, before the world jumped on Java and the Win32 API, which both are very dependent on threads.
These "deficiencies" are addressed by 2 other books of Stevens, in the form of the new edition of 'UNIX Network Programming'. In the first volume of this three-volume series the complete Unix network programming interface (both Sockets and the XTI) is explained, and contains sections on threads used in network programming. The second volume (to be published later this month) effectively expands the Interprocess Communications chapter of APUE and uses a lot of examples using the POSIX pthread
interface (according to the information available about this volume). Of course, these books refer to the current standards, and even to those still in draft (but not likely to change much).
All in all, these are not very pressing reasons to not check out this book. Practically all the material is still valid, and maybe the differences between the systems where APUE talks about are gone today.
You can buy this book at Amazon.
Table of Contents
Chapter 1. IntroductionIntroduction * Logging In * Files and Directories * Input and Output * Programs and Processes * ANSI C Features * Error Handling * User Identification * Signals * Unix Time Values * System Calls and Library Functions * Summary
Chapter 2. Unix Standardization and Implementations
Introduction * Unix Standardization * ANSI C * IEEE POSIX * X/Open
XPG3 * FIPS * Unix Implementations * System V Release 4 * 4.3+BSD *
Relationship of Standards and Implementations * Limits * ANSI C Limits
POSIX Limits * XPG3 Limits * sysconf
, pathconf
, and fpathconf
Functions * FIPS 151-1 Requirements * Summary of Limits * Indeterminate Run-Time Limits * Feature Test Macros * Primitive System Data Types * Conflicts Between Standards * Summary
Chapter 3. File I/O
Introduction * File Descriptors *
open
Function * creat
Function *
close
Function * lseek
Function *
read
Function * write
Function * I/O
Efficiency * File Sharing * Atomic Operations * dup
and
dup2
Functions * fcntl
Function *
ioctl
Function */dev/fd
* Summary
Chapter 4. Files and Directories
Introduction * stat
, fstat
, and
lstat
Functions * File Types * Set-User-ID and
Set-Group-ID * File Access Permissions * Ownership of New Files and
Directories * access
Function * umask
Function * chmod
and fchmod
Functions *
Sticky Bit * chown
, fchown
, and
lchown
Functions * File Size * File Truncation *
Filesystems * link
, unlink
,
remove
, and
rename Functions * Symbolic
Links * symlink
and readlink
Functions *
File Times * utime
Function * mkdir
and
rmdir
Functions * Reading Directories *
chdir
, fchdir
, and getcwd
Functions * Special Device Files * sync
and
fsync
Functions * Summary of File Access Permission Bits
* Summary
Chapter 5. Standard I/O Library
Introduction * Streams and FILE
Objects * Standard Input,
Standard Output, and Standard Error * Buffering * Opening a Stream *
Reading and Writing a Stream * Line-at-a-Time I/O * Standard I/O
Efficiency * Binary I/O * Positioning a Stream * Formatted I/O *
Implementation Details * Temporary Files * Alternatives to Standard
I/O * Summary
Chapter 6. System Data Files and Information
Introduction * Password File * Shadow Passwords * Group File *
Supplementary Group IDs * Other Data Files * Login Accounting * System
Identification * Time and Date Routines * Summary
Chapter 7. The Environment of a Unix Process
Introduction * main
Function * Process Termination *
Command-Line Arguments * Environment List * Memory Layout of a C
Program * Shared Libraries * Memory Allocation * Environment Variables
* setjmp
and longjmp
Functions *
getrlimit
and setrlimit
Functions * Summary
Chapter 8. Process Control
Introduction * Process Identifiers * fork
Function *
vfork
Function * exit
Functions *
wait
and waitpid
Functions *
wait3
and wait4
Functions * Race Conditions
* exec
Functions * Changing User IDs and Group IDs *
Interpreter Files * system Function * Process Accounting * User
Identification * Process Times * Summary
Chapter 9. Process Relationships
Introduction * Terminal Logins * Network Logins * Process Groups *
Sessions * Controlling Terminal * tcgetpgrp
and
tcsetpgrp
Functions * Job Control * Shell Execution of
Programs * Orphaned Process Groups * 4.3+BSD Implementation * Summary
Chapter 10. Signals
Introduction * Signal Concepts * signal
Function *
Unreliable Signals * Interrupted System Calls * Reentrant Functions *
SIGCLD
Semantics * Reliable Signal Terminology and
Semantics * kill
and raise
Functions *
alarm
and pause
Functions * Signal Sets *
sigprocmask
Function * sigpending
Function *
sigaction
Function * sigsetjmp
and
siglongjmp
Functions * sigsuspend
Function *
abort
Function * system
Function *
sleep
Function * Job-Control Signals * Additional
Features * Summary
Chapter 11. Terminal I/O
Introduction * Overview * Special Input Characters * Getting and
Setting Terminal Attributes * Terminal Option Flags *
stty
Command * Baud Rate Functions * Line Control
Functions * Terminal Identification * Canonical Mode * Noncanonical
Mode * Terminal Window Size * termcap
,
terminfo
, and curses
* Summary
Chapter 12. Advanced I/O
Introduction * Nonblocking I/O * Record Locking * Streams * I/O
Multiplexing * select
Function * poll
Function * Asynchronous I/O * System V Release 4 * 4.3+BSD *
readv
and writev
Functions *
readn
and writen
Functions * Memory Mapped
I/O * Summary
Chapter 13. Daemon Processes
Introduction * Daemon Characteristics * Coding Rules * Error Logging *
SVR4 Streams log
Driver * 4.3+BSD syslog
Facility * Client-Server Model * Summary
Chapter 14. Interprocess Communication
Introduction * Pipes * popen
and pclose
Functions * Coprocesses * FIFOs * System V IPC * Identifiers and Keys
Permission Structure * Configuration Limits * Advantages and Disadvantages * Message Queues * Semaphores * Shared Memory * Client-Server Properties * Summary
Chapter 15. Advanced Interprocess Communication
Introduction * Stream Pipes * Passing File Descriptors * System V
Release 4 * 4.3BSD * 4.3+BSD * An Open Server, Version 1 *
Client-Server Connection Functions * System V Release 4 * 4.3+BSD * An
Open Server, Version 2 * Summary
Chapter 16. A Database Library
Introduction * History * The Library * Implementation Overview *
Centralized or Decentralized? * Concurrency * Source Code *
Performance * Summary
Chapter 17. Communicating with a PostScript Printer
Introduction * PostScript Communication Dynamics * Printer Spooling *
Source Code Summary
Chapter 18. A Modem Dialer
Introduction * History * Program Design * Data Files * Server Design *
Server Source Code * Client Design * Client Source Code * Summary
Chapter 19. Pseudo Terminals
Introduction * Overview * Opening Pseudo-Terminal Devices * System V
Release 4 * 4.3+BSD * pty_fork
Function *
pty
Program * Using the pty
Program *
Advanced Features * Summary
Appendix A. Function Prototypes
Appendix B. Miscellaneous Source Code
Our Header File * Standard Error Routines
Appendix C. Solutions to Selected Exercises
Bibliography
Index
Review: Advanced Programming in the Unix Environment More Login
Review: Advanced Programming in the Unix Environment
Related Links Top of the: day, week, month.
Slashdot Top Deals