1430 Appendix F
processes. All four processes carry on to execute the next fork(), each creating a
further child. Consequently, a total of seven new processes are created.
24-2. A solution is provided in the file procexec/vfork_fd_test.c in the source code
distribution for this book.
24-3. If we call fork(), and then have the child call raise() to send itself a signal such as
SIGABRT, this will yield a core dump file that closely mirrors the state of the parent at
the time of the fork(). The gdb gcore command allows us to perform a similar task for
a program, without needing to change the source code.
24-5. Add a converse kill() call in the parent:
if (kill(childPid, SIGUSR1) == -1)
errExit("kill")
And in the child, add a converse sigsuspend() call:
sigsuspend(&origMask); /* Unblock SIGUSR1, wait for signal */
Chapter 25
25-1. Assuming a two’s complement architecture, where –1 is represented by a bit
pattern with all bits on, then the parent will see an exit status of 255 (all bits on in the
least significant 8 bits, which are all that is passed back to the parent when it calls
wait()). (The presence of the call exit(–1) in a program is usually a programmer error
resulting from confusion with the –1 return used to indicate failure of a system
call.)
Chapter 26
26-1. A solution is provided in the file procexec/orphan.c in the source code distribution
for this book.
Chapter 27
27-1. The execvp() function first fails to exec the file xyz in dir1, because execute
permission is denied. It therefore continues its search in dir2, where it successfully
execs xyz.
27-2. A solution is provided in the file procexec/execlp.c in the source code distribution of
this book.
27-3. The script specifies the cat program as its interpreter. The cat program “interprets”
a file by printing its contents—in this case with the –n (line numbering) option
enabled (as though we had entered the command cat –n ourscript). Thus, we would
see the following:
1 #!/bin/cat -n
2 Hello world
27-4. Two successive fork() calls yield a total of three processes related as parent, child,
and grandchild. Having created the grandchild process, the child immediately
exits, and is reaped by the waitpid() call in the parent. As a consequence of being