Quiz #1 (September 18, 2003)         Name: Solution by Xiuwen Liu

  COP4610  CGS5765   Recitation Section: _____  Last 4 SSN: ______

 

COP4610, Department of Computer Science, Florida State University, Fall 2000

 

Points: 100 points

 

1.      (15 points) What is an operating system? What are the four basic function modules of an operating system? (Hint: Device management is one of the function modules.)

An operating system is the system software between the hardware and application programs and other system software. It manages hardware resources and provides services to application programs through system calls.

The four basic function modules are device management, process and resource management, memory management and file management.

2.      (20 points, 10 points each) Suppose the disk request queue contains a set of references for blocks on tracks 12, 137, 29, 201, 269,  and 7 in the order the requests are received. We assume the head is currently at track 100, there is no further request, and the track range is from 0 to 511.

a.       Suppose the shortest-seek-time-first algorithm is used, list the requests in the order they are serviced and then give the total number of head movements in terms of tracks.

Here we use the shortest-seek-time-first algorithm. At the beginning the head is 100, the closest request is at track 137 and the head is moved to 137. At 137, 201 is the closest request and the next is 201. The requested are serviced in the following order:

            (100) -> 137 -> 201 -> 269 -> 29 -> 12 -> 7

The total number of head movements is

            (137-100) + (201-137) + (269-201) + (269-29) + (29-12) + (12-7) =

             37            +     64          +    68         +  240        + 17         + 5  =  431

 

b.      Suppose the Look algorithm is used and the head is moving toward higher-numbered tracks, list the given requests in the order they are serviced and then give the total number of head movements in terms of tracks.

Here we use the Look algorithm (note that this is not circular Look). Look algorithm moves the higher numbered tracks and serve the requests along the way and goes the other way (toward lower numbered tracks) and serve requests along the way. In this particular example, starting track 100, it will serve 137, 201, 269. It then will go the other way, and serve 29, 12, and 7. The requested are serviced in the following order:

            (100) -> 137 -> 201 -> 269 -> 29 -> 12 -> 7

The total number of head movements is

            (137-100) + (201-137) + (269-201) + (269-29) + (29-12) + (12-7) =

             37            +     64          +    68         +  240        + 17         + 5  =  431

 

3.      (30 points) Write a program in pseudo-code that will run “/usr/bin/ps –aef > tmp” as a background process.  You need to outline the key statements and system calls  (Hint: “>” indicates an output redirection.)

pid = fork();

If (pid ==0) { // Child

   fd = open(tmp,O_WRONLY); close(1); dup(fd); close(fd);

  myargv[0] = “/usr/bin/ls”, myargv[1] = “-aef”; myargv[2] = (char *)NULL;

  execvp(myargv[0], myargv);

}

// Parent: Since we need to run the command in background, it does nothing here

 

4.      (35 points) Suppose in a computer system, there are 16 different interrupt-driven I/O devices, there are 8 running processes who can request operations from any of the devices, and memory[1] = 0x100 (assuming memory is defined as int memory[1024]). At the end of each instruction cycle, the following is executed:

 

 

 

 

 

 

Answer the following questions:

a.       (10 points) In the above diagram, is “memory[0] = PC” necessary? (In other words, will the system work properly without the statement?) Why or why not?

The statement “memory[0] = PC” is necessary because we need to remember where the current process is interrupted so that we can resume the process from where it is stopped. Without the statement, the system will not work properly as we do not where to resume the interrupted process.

b.      (5 points) Where is the first instruction of the interrupt handler?

From the diagram, we know the CPU will start to execute the instruction whose address is given in memory[1] (which is 0x100). So the first instruction is at 0x100. Note that the first instruction is not at memory[1].

c.       (8 points) How does the interrupt handler know which of the 16 I/O devices generated the interrupt?

This is done by checking the done bit in the status register of each device controller.

d.      (7 points) How does the interrupt handler know which of the 8 processes requested the particular I/O operation that is causing the interrupt?

When a process requests an I/O operation, it calls a system call, which waits until the device is available, starts the I/O device, and then saves the necessary information in the device status table (at minimum, including which process requested this I/O operation). Then when an interrupt occurs, the OS determines which device generated the interrupt by checking (as in c.) and then the handler part of the device retrieves the information from the device status table and sends the information to the correct process. In summary, the interrupt handler gets the information from the device status table.

e.       (5 points) Suppose the CPU supports dual mode operation. Can an instruction in the user mode change the content of memory[1]? Why or why not?

No, an instruction in the user mode should not be able to change the content of memory[1]. Otherwise, a user program can change the interrupt handler, causing the system to be unsafe and untrusted. (By the way, in old PCs (there is only one mode), user programs were allowed  to change that and a lot of viruses took advantage of that to insert virus code.)