Appendix C. Solutions to Selected Exercises

Example Relevant Functions
C.1 notatty.c
Demonstrate bad interaction between
errno and printf.
Prints errno=25 (ENOTTY) when stdout
is redirected into a file.
open, printf, isatty (implied)
C.2 longpath.c
Create a deep directory tree
Show getcwd(3C) system limits.
mkdir, chdir, creat,
getcwd, path_alloc, realloc
C.3 getpwsvr4.c
Print encrypted password under SVR4.
getspnam
C.4 getpw44bsd.c
Print encrypted password under 4.3+BSD
getpwnam
C.5 prtime.c
Print date/time. Similar to date(1)
time, localtime, strftime
C.6 vfork3.c
Incorrect use of vfork:
Child overwrites parent stack area.
vfork (not under IRIX)
C.7 zombie.c
Create a zombie process
Watch ps(1) show it.
fork, err_sys (Stevens' lib),
sleep, system, exit
C.8 raise
Implementation of the raise(3C) function.
getpid, kill
C.9 lib.sun/sleepus.c
Implementation of uSec sleep using select.
select
C.10 lib.svr4/sleepus.c
Implementation of uSec sleep using poll.
poll
C.11 selectpipe.c
Calculation of pipe-capacity using select.
select pipe,
err_sys (Stevens' lib),
FD_ZERO, FD_SET,
write, printf, exit
C.12 sess/tdaemon2.c
Call daemon_init (background, detached
from tty process) and then try to obtain
the login name (w/o a controlling tty)
May not work in certain environments.
daemon_init (see 13.1),
close, getlogin,
sprintf, write, exit
C.13 ipc/fifo1.c
Opening a FIFO for read/write
without blocking.
unlink, mkfifo, open,
err_sys (Stevens' lib),
clr_fl (Stevens' lib),
exit