1428 Appendix F
Chapter 12
12-1. A solution is provided in the file sysinfo/procfs_user_exe.c in the source code
distribution for this book.
Chapter 13
13-3. This sequence of statements ensures that the data written to a stdio buffer is flushed
to the disk. The fflush() call flushes the stdio buffer for fp to the kernel buffer cache.
The argument given to the subsequent fsync() is the file descriptor underlying fp;
thus, the call flushes the (recently filled) kernel buffer for that file descriptor to
disk.
13-4. When standard output is sent to a terminal, it is line-buffered, so that the output of
the printf() call appears immediately, and is followed by the output of write(). When
standard output is sent to a disk file, it is block-buffered. Consequently, the output of
the printf() is held in a stdio buffer and is flushed only when the program exits (i.e.,
after the write() call). (A complete program containing the code of this exercise is
available in the file filebuff/mix23_linebuff.c in the source code distribution for
this book.)
Chapter 15
15-2. The stat() system call doesn’t change any file timestamps, since all it does is fetch
information from the file i-node (and there is no last i-node access timestamp).
15-4. The GNU C library provides just such a function, named euidaccess(), in the library
source file sysdeps/posix/euidaccess.c.
15-5. In order to do this, we must use two calls to umask(), as follows:
mode_t currUmask;
currUmask = umask(0); /* Retrieve current umask, set umask to 0 */
umask(currUmask); /* Restore umask to previous value */
Note, however, that this solution is not thread-safe, since threads share the process
umask setting.
15-7. A solution is provided in the file files/chiflag.c in the source code distribution for
this book.
Chapter 18
18-1. Using ls –li shows that the executable file has different i-node numbers after each
compilation. What happens is that the compiler removes (unlinks) any existing file
with the same name as its target executable, and then creates a new file with the
same name. It is permissible to unlink an executable file. The name is removed
immediately, but the file itself remains in existence until the process executing it
terminates.
18-2. The file myfile is created in the subdirectory test. The symlink() call creates a
relative link in the parent directory. Despite appearances, this is a dangling link,