You are on page 1of 4

Advanced Operating Systems (CS5500)

HW #4, Fall 2015


1. Explain the difference between preemptive and nonpreemptive scheduling.

The running task cannot be stopped until it finishes its execution. This is called Non-Preemptive
Scheduling.
The running task is interrupted for some time and resumed later when the priority task has
finished its execution. This is called preemptive scheduling.

2. Which of the following scheduling algorithms could result in starvation?


a. First-come, first-served
b. Shortest job first
c. Round robin
d. Priority

b. Shortest Job First


d.Priority

3. CPU scheduling such as SJF (shortest job first) is based on the precise prediction of CPU
burst times. One of the algorithm is exponential averaging. Check out the following
implementation and answer to questions (20 points)
float absolute(float n){
if (n < 0) return -n;
return n;
}
float eval_error(float *pred, float *actual, int size){
float err = 0;
int i;
for (i=0;i<size;i++){
// add each error value
err += absolute(pred[i] - actual[i]);
}

return err;
}
int main() {
float predicted_burst[100];
float actual_burst[]={20, 8, 7};
float alpha = 0.2;
int num_burst = 3;
int i;
predicted_burst[0] = 10;
for(i=0; i<num_burst; i++){
predicted_burst[i+1] = alpha * predicted_burst[i] + (1-alpha) * actual_burst[i];
printf("%f ", predicted_burst[i+1]); // Line P
}
printf("error = %f\n", eval_error(predicted_burst, actual_burst, num_burst)); // Line X
}
(a) What output will be displayed to the screen by Line P?
Put down all three values in order.

18.000000

10.000000

7.600000

(b) What output will be displayed to the screen by Line X?

error = 23.000000
4. Consider the following four processes of varying arrival times and CPU burst times.
* Assumptions
When there are multiple processes that arrive at the same time, the process with smaller
index goes first to the ready queue.
If a process goes back to the ready queue after running when new processes arrive,
new processes go first to the ready queue.
Process

Arrival Time

CPU Burst Time

P1

P2

P3

P4

(a) Draw a Gantt chart that illustrates the execution of these processes using preemptive SJF
(or shortest-remaining-time-first) scheduling algorithms. Calculate its average turnaround

time, waiting time, and average response time. When a new process has the same
remaining time with the running process, the running process keeps running. When there
are multiple processes with the same remaining time in the ready queue, the one that
comes first in the ready queue is selected.

P1
0

P1
1

P3

P1
5

P1

P2

P4
13

20

Avg wait time = 4.25


Avg Turn around time = 9
Avg Response time = 3.5

(b) Draw a Gantt chart that illustrates the execution of these processes using RR (quantum = 3)
scheduling algorithms. Calculate its average turnaround time, waiting time, and average
response time.

P1
0

P2
3

P3
6

P1
8

P4
11

P2
14

P4
16

P4
19

20

Avg waiting time = 6.25


Avg turn around time = 11.25
Avg response time = 2.5

5. Check out the following real time CPU scheduling information and answer to each question.

There are two processes P1. P2. The periods for P1 and P2 are 50 and 80. The processing
times are t1 = 30 for P1 and t2 = 25 for P2. The deadline for each process requires that it
complete its CPU burst by the start of its next period.
(a) Draw a Gantt chart when rate-monotonic scheduling is used. Does this algorithm satisfy
all the deadlines? Yes/No

No
(b) Draw a Gantt chart when earliest-deadline-first-scheduling is used. Does this algorithm
satisfy all the deadlines? Yes/No

Yes

You might also like