ptg10805159
924 Solutions to Selected Exercises Appendix C
Chapter 10
10.1 The program terminates the first time we send it a signal. The reason is that the
pausefunction returns whenever a signal is caught.
10.3 FigureC.11shows the stack frames.
stack frame
formain
stack frame
formain
stack frame
forsleep2
stack frame
forsig_int
stack frame
formain
stack frame
forsleep2
stack frame
forsig_int
stack frame
forsig_alrm
longjmp
stack frame
formain
stack frame
forsleep2
return to
main
bottom
of stack
processing
SIGINT
processing
SIGALRM
after
longjmp
Figure C.11 Stack frames beforeand afterlongjmp
Thelongjmpfromsig_alrmback tosleep2effectively aborts the call to
sig_int.Fromthis point,sleep2returns to main (recall Figure10.8).
10.4 We again have a race condition, this time between the first call toalarmand the
call to setjmp.Ifthe process is blocked by the kernel between these two
function calls, the alarm goes off, the signal handler is called, andlongjmpis
called. But sincesetjmpwas never called, the bufferenv_alrmis not set. The
operation oflongjmpis undefined if its jump buffer has not been initialized by
setjmp.
10.5 See ‘‘Implementing SoftwareTimers’’ by Don Libes (CUsers Journal,vol. 8, no.
11,Nov.1990) for an example. Acopy of this paper is available online at
http://www.kohala.com/start/libes.timers.txt.
10.7 If we simply called_exit,the termination status of the process would not show
that it was terminated by theSIGABRTsignal.
10.8 If the signal was sent by a process owned by some other user,the process has to
be set-user-ID to either root or to the owner of the receiving process, or thekill
attempt won’t work. Therefore, the real user ID provides moreinformation to
the receiver of the signal.