14 CS620 Spring 2008 Assignment 6

CS 620

Assignment 6

(Total 50 points)

Due Date: 04/17/2008 (Thursday)

The assignment is to be handed in class. No late assignments will be accepted.

1.(15 points)

An operating system uses multi-level feedback (with preemption) for CPU scheduling. There are 3 feedback queues with associated quanta 1, 2, and 3 time units.

Consider the following workload:

Process

Arrival Time

CPU Requirements

p1

1

6

p2

3

8

p3

6

4

p4

9

3

p5

11

5

 

[a.] Calculate the mean response time, observing from time 1 until all processes have completed.

[b.] Suppose that non-preemptive multi-level feedback was used instead. Calculate the mean response time, observing from time 1 until all processes have completed.

[c.] Calculate the mean response time of jobs when Round Robin is the CPU scheduling policy with time quantum = 2.

[d.] Calculate the mean response time of jobs when SRTN is used as the scheduling policy.

[e.] Calculate the mean response time of jobs when LIFO is used as the scheduling policy.

---------------

[Answer]

[a.] Calculate the mean response time, observing from time 1 until all processes have completed.

Preemptive Multilevel feedback queue

Process

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

Response

Time

P1

E1

E2

 w2

E2

W3 
W3
W3
W3

W3 

W3

W3

W3

W3

W3 

W3 

E3 

E3 

E3 

 

 

 

 

 

 

 

 

  18

P2

 

 

 E1

 W2

E2

W2

E2
W3

W3

W3

W3 

W3 

W3 

W3 

W3

W3 

W3 

W3 

E3 

E3 

E3 

W3 

W3 

W3 

 E3

 E3

  24

P3

 

 

 

 

E1

W2

E2

W2

E2

W3
W3
W3
W3
W3
W3
W3
W3
W3
W3
W3

E3

       

   17

P4

 

 

 

 

 

 

    E1 W2 W2 E2 E2                              5

P5

 

 

 

 

 

 

        E1 W2 W2 E2 E2 W3 W3 W3 W3 W3 W3 W3 E3 E3        14

  Mean Response time = 72/5

[b.] Suppose that non-preemptive multi-level feedback was used instead. Calculate the mean response time, observing from time 1 until all processes have completed.

Non preemptive MultiLevel FeedBack

Process

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

Response

Time

P1

E1

E2
E2
W3 
W3
W3

W3 

W3

W3

W3

W3

W3 

W3

W3 

W3 

E3 

E3 

E3 

 

 

 

 

 

 

 

 

  18

P2

 

 

W1 

 E1

 E2

 E2

W3 

W3 

W3 

W3 

W3 

W3

W3 

W3 

W3 

W3

W3 

W3 

E3 

E3 

E3 

W3 

W3 

W3 

 E3

 E3

  24

P3

 

 

 

 

W1

E1

E2

E2

W3
W3
W3
W3
W3
W3
W3
W3
W3
W3
W3
W3

E3

 

 

 

 

  17

P4

 

 

 

 

 

 

    W1 E1 W2 E2 E2                          

  5

P5

 

 

 

 

 

 

        E1 W2 W2 E2 E2 W3 W3 W3 W3 W3 W3 W3 E3 E3    

  14

 Mean Response time = 78/5

[c.] Calculate the mean response time of jobs when Round Robin is the CPU scheduling policy with time quantum = 2.

Round Robin (Suppose a new job has higher priority than a new run of an old job)

 

Process

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

Response

Time

P1

E

E

W
W

E

E

W

W

W

W

E

E

                            12

P2

 

 

E

E

W

W

E

E

W

W

W

W

W

W

E

E

W

W

W

W

W

E

E

      21

P3

 

 

 

 

 

W

W
W

E

E

W

W W

W

W

W

W

W

E E             15

P4

 

 

 

 

 

    W W W W E E W W W W W W E           13

P5

 

 

 

 

 

          W W W W W W E E W W W W W E E E 16


      Mean Response Time = 77/5

[d.] Calculate the mean response time of jobs when SRTN is used as the scheduling policy.

SRTN

Process

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

Response

Time

P1

E

E E E E E                                         6

P2

 

 

W W W W W W W W W W W W W W W W E E E E E E E E 24

P3

 

        W E E E E                                 5

P4

 

              W W E E E                           5

P5

 

                  W W W E E E E E                 8


      Mean Response Time = 48/5
 

[e.] Calculate the mean response time of jobs when LIFO is used as the scheduling policy.

LIFO

Process

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

Response

Time

P1

E

E

W

W

W

W

W
W
W

W

W

W

W

W  W  W  W  W  W  W  W  W  E  E  E  E  26

P2

 

 

E

E

E

W

W

W

W

W

W

W

W W W W E E E E E         20

P3

 

 

 

 

E

E

E

W W W W W W W W

E

                  12

P4

 

 

 

 

 

      E E W W W W W E                     8

P5

 

 

 

 

 

 

        E E E E E                       5


      Mean Response Time = 71/5


---------------

2. (5 points )

Many CPU scheduling algorithms are parameterized. For example, the RR algorithm requires a parameter to indicate the time slice. Multilevel feedback queues require parameters to define the number of queues, the scheduling algorithms for each queue, the criteria used to move processes between queues, and so on.

The algorithms are thus really sets of algorithms (for example, the set of RR algorithms for all time slices, and so on). One set of algorithms may include another (for example, the FCFS algorithm is the RR algorithm with an infinite time quantum). What (if any) relation holds between the following pairs of sets of algorithms?
a. Priority and SJF
b. Multilevel feedback queues and FCFS
c. Priority and FCFS
d. RR and SJF
e. LCFS preemptive and SRTN

---------------

[Answer]

a. The shortest job has the highest priority.
b. The lowest level of MLFQ is FCFS.
c. FCFS gives the highest priority to the job having been in existence the longest.
d. None
e. SRTN is an ordered LCFS preemptive with the shortest job last.

3. (8 points)

Which of the following scheduling algorithms could result in starvation? Give a brief explanation in each case.
a. First come first served (FCFS)
b. Shortest job first (SJF)
c. MultiLevel Feedback (MLF)
d. Last come first served (LCFS)

[Answer]

a. First come first served (FCFS): This algorithm cannot lead to starvation since a process will get a chance to execute, no matter how long it has to wait before that because of longer processes ahead of it in the queue.
b. Shortest job first (SJF): This algorithm is supposed to be the optimal since it provides minimum average waiting time for a given set of processes. It moves the shorter process ( next process with shortest burst time) ahead of the longer one and thus this algorithm reduces the wait time of shorter processes, but could lead to starvation of longer processes.
c. MultiLevel Feedback (MLF): This algorithm is to separate processes according to the characteristics of their CPU bursts. If a process uses too much CPU time, it will be moved to a lower-priority queue. A process that waits too long in a lower-priority queue may be moved to a higher-priority queue. So it prevents starvation.
d. Last come first served (LCFS): With this algorithm, the process that requests the CPU last is allocated the CPU first. If there are always new processes coming, the oldest processes could be starved by the new ones.
---------------

4 (5 points)

  #include <sys/types.h>
  #include <stdio.h>
  #include <unistd.h>

  int a = 8;
  int b = 2;
 
  int main(){
     pid_t pid;

     if ((pid = fork()) == 0){ /*child process */
       a += 3;
       b = a + 4;
     }
     else if( pid>0 ){ /*parent process*/
       a += 4;
       b += a;
       printf("Parent: a = %d, b= %d,", a, b); /* LINE A */
       exit(0);
     }
  }

In the above program, what will be the output at LINE A? Explain your answer.


---------------

[Answer]

The output at line A will be "Parent: a = 12, b = 14" since the parent process creates a child process which will execute separately from the parent process. The return code of fork() for a parent process is a nonzero pid which is the pid of the child process created. Thus the else condition is satisfied and the message is displayed after the parent process executes "a += 4; b += a". Also the value of 'a' and 'b' are not changed before executing "a += 4; b += a" in the parent process.

5. (6 points)

Distinguish between:
a. (2 points) creating a thread versus creating a process.
b. (2 points) user-level threads versus kernel-level threads in terms of how they are scheduled.
c. (2 points) invoking an ordinary procedure versus invoking a thread create procedure.
Your answer should address the internal operating system actions.

[Answer]

a. A process creation results in memory being allocated for program instructions and data, as well as thread-like storage. Code may also be loaded into the allocated memory.
When creating a thread, a context must be created, including a register set storage location for storage during context switching, and a local stack to record the procedure call arguments, return values, and return address, and thread-local storage.
b. Kernel-level threads are scheduled by the operating system. On the contrary, user-level threads are managed by a thread library and the kernel is unaware of them. There is no kernel intervention. They are flexible and the cost is low. To run on a CPU, user-level threads must ultimately be mapped to an associated kernel-level thread, although this mapping may be indirect and may use a lightweight process.
c. There is only 1 "thread" of execution in case of an ordinary procedure call. The program counter for the program jumps to the procedure. In the case of thread create procedure, the thread and the calling program execute currently. That is, there are 2 "threads" of execution. Both the thread and the calling program are in the ready queue.
---------------

6. (4 points)

Throughput, response time and fairness are the common performance metrics used to evaluate a scheduling algorithm.

a. What is the relationship between throughput and response time?
b. What is the relationship between fairness and response time?

[Answer]

a. Throughput is the number of jobs which are serviced per unit time. Response time is the time from when a job request is made until the job is finished, that is the sum of waiting time and service time. The lower response time a scheduling algorithm has, the higher throughput will be using such scheduling algorithm.
b. Fairness measures that if a scheduling algorithm is shared among jobs in a fair way. Usually more fairness results in higher response time.

A scheduling algorithm aims to accomplish the following goals:
1. Minimize the response time;
2. Maximize the throughput;
3. Achieve fairness.
---------------

7. (3 points)

Consider a variant of the RR scheduling algorithm where the entries in the ready queue are pointers to the PCBs.

a. What would be the effect of putting two pointers to the same process in the ready queue?
b. What would be the major advantages and disadvantages of this scheme?
c. How would you modify the basic RR algorithm to achieve the same effect without duplicate pointers?

[Answer]

a. In effect, that process will have increased its priority since by getting time more often it is receiving preferential treatment.
b. The advantage is that more important jobs could be given more time, in other words, higher priority in treatment. The consequence, of course, is that shorter jobs will suffer.
c. Allow a longer amount of time to processes deserving higher priority, in other words, have two or more quantums possible in the round-robin scheme.

8. (4 points)

Consider the following preemptive priority-scheduling algorithm based on dynamically changing priorities. Larger priority numbers imply higher priority. when a process is waiting for the CPU (in the ready queue, but not running), its priority changes at a rate a; when it is running, its priority changes at a rate b. All processes are given a priority of 0 when they enter the ready queue. the parameters a and b can be set to given many different scheduling algorithms.

a. what is the algorithm that result from b > a > 0?
b. what is the algorithm that result from a < b < 0?

[Answer]

a.
FCFS
b.
LIFO


****************************************************************************************************
Return to the CS 620 Home Page