CMSC 412 Midterm #1 (Spring 2003)

 

1.)                  (20 points) Define and explain the following terms:

a)                   Critical Section

A section of code that needs to be protected by mutual exclusion, any solution should also ensure that there is bounded waiting time and ensure forward progress.

b)                   Safe Sequence

A sequence of resource requests that allow a system to go from the current state the completion of all jobs in the system without entering deadlock. This can be done by ordering all processes such that any process can run to completion with its currently allocated resources plus those resources available at the start of the sequence and those held by processes earlier in the sequence.

c)                   Deadlock

When a system is unable to make forward progress.  Requires the four necessary (but not sufficient conditions: hold & wait, circular wait, non-preemption, and mutual exclusion.

d)                   Dispatcher

The lowest level part of the scheduler responsible for switching which process is currently running on the system.

2.)                 (25 points) Synchronization: You need to synchronize the process of getting and making coffee in the CS department lounge.  In the department, there are two types of coffee urns (regular and decaf) and one coffee maker.  If someone goes to get a cup of coffee of one type, and that pot is empty they make a new pot of that type of coffee. Provide a solution using semaphores (include variable declarations and initial semaphore values) to the coffee problem that ensures:

·         Only one person at a time is taking coffee out of the decaf urn

·         Only one person at a time is taking coffee out of the regular urn

·         Only one urn is on the coffee maker at a time

·         If one type of urn is being made and the other has coffee, people can get the type of coffee that is available.

 

Semaphore decaf(1), regular(1), maker(1)

Coffee Drinker(Boolean usesDecaf):

If (usesDecaf) {

    P(decaf)

    If (isEmpty(usesDecaf)) {

        P(maker);

        // make decaf coffee

       V(maker);

    }

     // take decaf coffee

    V(decaf);

} else {
    P(regular)

    If (isEmpty(usesDecaf)) {

        P(maker);

        // make regular coffee

       V(maker);

    }

     // take regular coffee

    V(regular);

}

3.)                 (20 Points) Sally Smart decides to test project #1 in the following way: she implements the loading of the user program from the elf file, but does not implement the user segments and instead plans to test running a user program within the kernel segment.  Her argument is that since she is testing, it doesn’t matter that memory security is not provided for the user process. Assuming she is correct about the memory security issue, would her solution work?  Explain your answer.

No, here solution will not work since the user space programs expect their virtual addresses to start at 0.  If she runs using the kernel segment, the address 0 will be part of the kernel’s code.

4.)                  (15 points) In an OS kernel, give two reasons why are system calls done indirectly via a system call number and trap rather than simply calling a subroutine in the kernel?

To decouple versions of the OS kernel from user space programs.

To control what functions in the kernel can be called from user space.

5.)                  (20 points) OS Structure

a)                   (10 points) Give an example of a mechanism and an example of a policy in an OS

policy – only the student’s and their TAs can read files.

Mechanism – File access is controlled based on access control lists.

b)                    (10 points) Why did your kernel need to check both the base and extent of the string passed to the printString system call even if your version of libuser.c already checked the pointer?

So programs can’t trick the kernel into reading memory that is out of range.  Need to check extent check for the case when the starting pointer is valid, but the end is past the end of a process’s memory.