Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

382 Signals Chapter 10


10.10 Write a program that callssleep(60)in an infinite loop. Every five times through the
loop (every 5 minutes), fetch the current time of day and print thetm_secfield. Run the
program overnight and explain the results. How would a program such as thecron
daemon, which runs every minute on the minute, handle this situation?
10.11 Modify Figure3.5 as follows: (a) changeBUFFSIZEto 100; (b) catch theSIGXFSZsignal
using thesignal_intrfunction, printing a message when it’s caught, and returning
from the signal handler; and (c) print the return value fromwriteif the requested number
of bytes wasn’t written. Modify the softRLIMIT_FSIZEresource limit (Section 7.11) to
1,024 bytes and run your new program, copying a file that is larger than 1,024 bytes. (Try
to set the soft resource limit from your shell. If you can’t do this from your shell, call
setrlimitdirectly from the program.) Run this program on the different systems that
you have access to. What happens and why?
10.12 Write a program that callsfwritewith a large buffer (about one gigabyte). Beforecalling
fwrite,callalarmto schedule a signal in 1 second. In your signal handler,print that the
signal was caught and return. Does the call tofwritecomplete? What’s happening?
Free download pdf