Advanced Programming in the
UNIX Environment

by W. Richard Stevens
Addison-Wesley Professional Computing Series
0-201-56317-7 * Hardcover * 768 pages * ©1992
[Buy this book]

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

Example Relevant Functions
12.1 Large non-blocking write read, write,
set_fl (Stevens' lib, Sec 3.5),
clr_fl (Stevens' lib, Sec 3.5)
12.2 lock_reg: lock/unlock a region of a file
Handy macros based on the above:
read_lock (Stevens' lib),
readw_lock (Stevens' lib),
write_lock (Stevens' lib),
writew_lock (Stevens' lib),
12.3 lock_test:
Test if a file region is locked by another process
is_readlock, is_writelock
Handy macros based on the above
12.4 Example of deadlock detection creat, fork,
(Sec 8.8)
writew_lock (Sec. 12.2)
12.5 Daemon startup code:
prevent running multiple daemon copies
open, write_lock, ftruncate,
write, fcntl
12.6 Bad program example:
Problems with locking relative to end of file
Getting out of locks (resource limit) in the kernel.
open, write,
writew_lock, un_lock, ENOLCK
12.7 Is mandatory locking supported by the system ?
(Note: mandatory locking is part of SVR4 but not POSIX.1)
open, write, fstat, fchmod,
fork, waitpid, lseek, read,
read_lock, write_lock, set_fl (Sec 3.5),
12.8 isastream:
Check if descriptor is a streams device
ioctl (with   I_CANPUT)
12.9 Test program for isastream above open, isastream
12.10 List the names of the modules on a stream isastream, ioctl, calloc
12.11 catgetmsg:
Copy stdin to stdout using getmsg (streams)
getmsg, write
12.12 writen:
Write N bytes to a descriptor
12.13 readn:
Read N bytes from a descriptor
12.14 Copy a file (fast) using memory-mapped I/O open, fstat, lseek, write, memcpy,
mmap, munmap (implicit on exit)

[Buy this book]