Assignment2 - Which of the problems mentioned earlier by...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CSci 5103 (Fall 2010) Assignment 2 (100 points) Due September 30, 2010 This part of the assignment must be done individually . Question 1: Consider the following unreliable implementation of sleep given in the book by Stevens and Rago (available online through the course webpage), in Chaper 10, on page 257. #include <signal. h> #include <unistd. h> static void sig_alrm(int signo) { /* nothing to do, j ust return to wake up the pause */ } unsigned int sleep1(unsigned int nsecs) { if (signal(SIGALRM, sig_alrm) == SIG_ERR) return(nsecs) ; alarm(nsecs) ; /* start the timer */ pause() ; /* next caught signal wakes us up */ return(alarm(0) ) ; /* turn off timer, return unslept time */ } Stevens and Rago outline three problems with this code. A more reliable implementation of sleep is given by Steven and Rago on pages 285-286.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Which of the problems mentioned earlier by them are now corrected in this code? With this more reliable implementation of sleep, explain what will happen in the following case. We do an alarm( 10) and 3 wall clock seconds later do a sleep(5) , what happens? The sleep will return in 5 seconds (assuming that some other signal isn’t caught in that time), but will another SIGALRM be generated 2 seconds later? If yes, explain how the code will ensure delivery of the SIGALRM for the original alarm setting. If no, then modify this code to achieve that functionality. Also, the originally intended disposition for SIGALRM should be preserved. Question 2: From Tanenbaum’s book (Third edition) Problem 7 from Chapter 2. Question 3: From Tanenbaum’s book (Third edition) Problem 14 from Chapter 2....
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online