The Linux Programming Interface

(nextflipdebug5) #1

1432 Appendix F


The problem is that grep will be part of the same process group as ourprog, and
therefore the killpg() call will also terminate the grep process. This is probably not
desired, and is likely to confuse users. The solution is to use setpgid() to ensure that
the child processes are placed in their own new group (the process ID of the first
child could be used as the process group ID of the group), and then signal that process
group. This also removes the need for the parent to make itself immune to the signal.
34-5. If the SIGTSTP signal is unblocked before raising it again, then there is a small
window of time (between the calls to sigprocmask() and raise()) during which, if the
user types a second suspend character (Control-Z), the process will be stopped while
still in the handler. Consequently, two SIGCONT signals will be required to resume the
process.

Chapter 35


35-3. A solution is provided in the file procpri/demo_sched_fifo.c in the source code
distribution for this book.

Chapter 36


36-1. A solution is provided in the file procres/rusage_wait.c in the source code
distribution for this book.
36-2. A solution is provided in the files rusage.c and print_rusage.c in the procres
subdirectory in the source code distribution for this book.

Chapter 37


37-1. A solution is provided in the file daemons/t_syslog.c in the source code distribution
for this book.

Chapter 38


38-1. Whenever a file is modified by an unprivileged user, the kernel clears the file’s set-
user-ID permission bit. The set-group-ID permission bit is similarly cleared if the
group-execute permission bit is enabled. (As detailed in Section 55.4, the
combination of having the set-group-ID bit on while the group-execute bit is off has
nothing to do with set-group-ID programs; instead, it is used to enable mandatory
locking, and for this reason modifications to such a file don’t disable the set-group-
ID bit.) Clearing these bits ensures that if the program file is writable by arbitrary
users, then it can’t be modified and still retain its ability to give privileges to users
executing the file. A privileged (CAP_FSETID) process can modify a file without the
kernel clearing these permission bits.

Chapter 44


44-1. A solution is provided in the file pipes/change_case.c in the source code distribution
for this book.
44-5. It creates a race condition. Suppose that between the time the server sees end-of-
file and the time it closes the file reading descriptor, a client opens the FIFO for
Free download pdf