| 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),
un_lock
|
fcntl
|
12.3 | lock_test:
Test if a file region is locked by another process
is_readlock,
is_writelock
Handy macros based on the above
|
fcntl
|
12.4 | Example of deadlock detection |
creat,
fork,
TELL_PARENT,
WAIT_PARENT,
TELL_CHILD,
WAIT_CHILD,
(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),
TELL_WAIT, TELL_CHILD,
WAIT_PARENT
|
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
|
write
|
12.13 | readn:
Read N bytes from a descriptor
|
read
|
12.14 | Copy a file (fast) using memory-mapped I/O |
open,
fstat,
lseek,
write,
memcpy,
mmap,
munmap (implicit on exit)
|