Docsity

Exam 2 - Operating System - Computer Science | CS 999, Exams of Computer Science

Toggle sidebar
bg1
CS 471: Operating Systems
In-Class Exam 2
Name:________________________
April 20 2006
Instructions: This exam is open book, open notes. The work you turn in must be your own. To receive credit
you must sign the honor pledge at the end of the exam.
1. (10 pts) Consider the bakery algorithm for critical sections. n processes have the shared data:
boolean choosing[n];
int number[n];
which are initialized to false and 0 respectively. Each process has a unique number, i, each executes the
following code:
do {
choosing[ i ] = true;
number[ i ] = max( number[0], number[1], …, number[n – 1] ) + 1;
choosing[ i ] = false;
for ( j = 0; j < n; j++ ) {
while ( choosing[ j ] ) ;
while ( (number[ j ] != 0 ) &&
( ( number[ j ], j ) < ( number[ i ], i ) ) ;
}
critical section
number[ i ] = 0;
remainder section
} while ( 1 );
Why must the second while loop check both the number array and the values of i and j? Hint: Part of you
answer should explain why two processes can sometimes have the same value for their number[i].
2. (10 pts) Explain why the semaphore calls wait and signal must be provided as OS calls rather than as
user written functions.
1
pf3
pf4
pf5

Partial preview of the text

Download Exam 2 - Operating System - Computer Science | CS 999 and more Exams Computer Science in PDF only on Docsity!

CS 471: Operating Systems

In-Class Exam 2

Name:________________________

April 20 2006

Instructions: This exam is open book, open notes. The work you turn in must be your own. To receive credit

you must sign the honor pledge at the end of the exam.

1. (10 pts) Consider the bakery algorithm for critical sections. n processes have the shared data:

boolean choosing[n]; int number[n];

which are initialized to false and 0 respectively. Each process has a unique number, i, each executes the

following code:

do { choosing[ i ] = true; number[ i ] = max( number[0], number[1], …, number[n – 1] ) + 1; choosing[ i ] = false; for ( j = 0; j < n; j++ ) { while ( choosing[ j ] ) ; while ( (number[ j ] != 0 ) && ( ( number[ j ], j ) < ( number[ i ], i ) ) ; } critical section number[ i ] = 0; remainder section } while ( 1 );

Why must the second while loop check both the number array and the values of i and j? Hint: Part of you

answer should explain why two processes can sometimes have the same value for their number[i].

2. (10 pts) Explain why the semaphore calls wait and signal must be provided as OS calls rather than as

user written functions.

  • Data structures: binary-semaphore S1, S2; int C:
  • Initialization: S1 = 1; S2 = 0;

C = initial value of counting semaphore S;

  • wait operation wait( S1 ); C--; if ( C < 0 ) { signal( S1 ); wait( S2 ); } signal( S1 );
  • signal operation wait( S1 ); C++; if ( C <= 0 ) signal( S2 ); else signal( S1 );
  1. (10 pts) a. The implementation of counting semaphores from the slides reproduced above uses binary

semaphores. Why are two binary semaphores needed in this implementation?

b) If an OS provides only binary semaphores, can users create their own efficient counting semaphores?

Explain why or why not.

4. (10 pts) Older operating systems preallocated of all resources to a process before it would start the process.

These systems could not deadlock. Why? (Use the deadlock conditions in your response).

8. (5 pts) It generally makes more sense for processes to share segments than to share pages. Why?

9. (10 pts) In segmented virtual memory, uninitialized pointers often result in errors reported by the OS as

“segmentation errors.”

a) Why are these regarded as segmentation errors to the OS?

b) Why do some uninitialized pointers not produce segmentation errors?

10. (15 pts) a) If company “ReallyCheapComputers, Inc.” provided a virtual memory operating system without

using dirty bits, what would be the performance impact? Explain why.

b) If they also did not use modify bits, what would be the performance impact? Again, explain why.

c) If they also did not provide lock bits, what would be the impact? Again, explain.

11. (10 pts) a) How can operating systems detect thrashing efficiently?

b0 Thrashing can generally be stopped by swapping out one or more processes. Explain why.

Pledged: I have neither given nor received help on this exam.

Signature