CS 446/646 Principles of Computer Operating Systems

Spring 2009

Homework 2

Due on Monday, March 9 at 12:00 pm

 

Solve the following problems from the text book (Silberschatz, 8th edition):

Chapter 4:

13: The program shown in Figure 4.14 uses the Pthreads API. What would be output from the program at LINE C and LINE P?.

Figure 4.14

17: The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, .... Formally, it can be expressed as:

Fibonacci

Write a multithreaded program that generates the Fibonacci series using either the Java, Pthreads, or Win32 thread library. This program should work as follows: The user will enter on the command line the number of Fibonacci numbers that the program is to generate. The program will then create a separate thread that will generate the Fibonacci numbers, placing the sequence in data that is shared by the threads (an array is probably the most convenient data structure).When the thread finishes execution, the parent thread will output the sequence generated by the child thread. Because the parent thread cannot begin outputting the Fibonacci sequence until the child thread finishes, this will require having the parent thread wait for the child thread to finish using the techniques described in Section 4.3.

Chapter 5:

10: Discuss how the following pairs of scheduling criteria conflict in certain settings.

a. CPU utilization and response time

b. Average turnaround time and maximum waiting time

c. I/O device utilization and CPU utilization

12: Consider the following set of processes,with the length of the CPU-burst time given in milliseconds:

Processes

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.

a. DrawfourGantt charts illustrating the execution of these processes using FCFS, SJF, a nonpreemptive priority (a smaller priority number implies a higher priority), and RR (quantum = 1) scheduling.

b. What is the turnaround time of each process for each of the scheduling algorithms in part a?

c. What is the waiting time of each process for each of the scheduling algorithms in part a?

d. Which of the schedules in part a results in the minimal average waiting time (over all processes)?

15: Consider a system running ten I/O-bound tasks and one CPU-bound task. Assume that the I/O-bound tasks issue an I/O operation once for every millisecond of CPU computing and that each I/O operation takes 10 milliseconds to complete. Also assume that the context switching overhead is 0.1millisecond and that all processes are long-running tasks. What is the CPU utilization for a round-robin scheduler when:

a. The time quantum is 1 millisecond

b. The time quantum is 10 milliseconds

Chapter 6:

9: The first known correct software solution to the critical-section problem for two processes was developed by Dekker. The two processes, P0 and P1, share the following variables:

boolean flag[2]; /* initially false */
int turn;

The structure of process Pi (i == 0 or 1) is shown in Figure 6.25; the other process is Pj (j == 1 or 0). Prove that the algorithm satisfies all three requirements for the critical-section problem.

do {
flag[i] = TRUE;

while(flag[j]){
  if (turn ==j ){
	  flag[i] = FALSE;
		while(turn==j)
				;  // do nothing
		flag[i] = TRUE;
	}
}

// critical section

turn = j;
flag[i] = FALSE;

// remainder section

} while (TRUE);

12: Explain why spinlocks are not appropriate for single-processor systems yet are often used in multiprocessor systems.

Note: Source codes of programs in the textbook (including the date client and server) can be found here.

What to turn in: A softcopy of your solutions (could be a scanned version of the hard copy of the solutions) to be uploaded to WebCT.