TUTORIAL 1(Operating systems TIT/TCS 503) SOLUTIONS Ques 1

TUTORIAL 1(Operating systems TIT/TCS 503)
SOLUTIONS
Ques 1:
Why it is important for scheduler to distinguish I/O bound programs from CPU bound
Programs?
Ans:
I/O-bound programs have the property of performing only a small amount of computation
before performing I/O. Such programs typically do not use up their entire CPU quantum. CPUbound programs, on the other hand, use their entire quantum without performing any
blocking I/O operations. Consequently, one could makebetter use of the computer's resources
by giving higher priority to I/O-bound programs and allow them to execute ahead of the CPUbound programs.
Ques 2:
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.
Ans:
Ans: CPU utilization and response time: CPU utilization is increased if the overheads
associated with context switching is minimized. The context switching overheads could be
lowered by performing context switches infrequently. But This could however result in
increasing the response time for processes.
Average turnaround time and maximum waiting time: Average turnaround time is minimized
by executing the shortest tasks first. Such a scheduling policy could however starve longrunning tasks and thereby increase their waiting time.
I/O device utilization and CPU utilization: CPU utilization is maximized by running long-running
CPU-bound tasks without performing context switches. I/O device utilization is maximized by
scheduling I/O-bound jobs as soon as they become ready to run,thereby incurring the
overheads of context switches.So if I/O device utilization is increases the CPU utilization may
get down and vice versa
Ques 3:Consider the following set of processes, with the length of the CPU-burst
time given in milliseconds:
Process Burst Time Priority
P1
10
3
P2
1
1
P3
2
3
P4
1
4
P5
5
2
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5,
all at time 0.
a. Draw four Gantt 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)?
A)FCFS:
P1
0
P2
10
P3
11
P4
13
P5
14
19
SJF:
P2 P4 P3
P5
0 1 2
4
non-preemptive priority :
P2 P5
P1
0 1
6
P1
9
19
P3
16
P4
18 19
RR:
P1 P2 P3 P4 P5 P1 P3 P5 P1 P5 P1 P5 P1 P5 P1 P1 P1 P1 P1
0 1 2 3
4
5 6
7
8 9 10 11 12 13 14 15
16 17 18 19
b. Turnaround time
P1
P2
P3
P4
P5
FCFS
10
11
13
14
19
RR
19
2
7
4
14
SJF PRIORITY
19
16
1
1
4
18
2
19
9
6
c. Waiting time (turnaround time - burst time)
FCFS
P1
P2
P3
P4
P5
AWT:
RR
0
10
11
13
14
9.6
SJF
9
1
5
3
9
5.4
Priority
9
6
0
0
2
16
1
18
4
1
3.2
8.2
d. Shortest Job First (3.2 ms).
Ques 4: Is a non preemptive scheduling algorithm a good choice for an interactive system?
Briefly, why?
Ans: No. Once a process gains control of the CPU, it retains control until it blocks or it
terminates. A process could execute for an extended period of time doing neither due to no
preemption. Other processes on the system would not be able to execute, producing
unacceptable response time.
Ques 5:
On a system using multilevel feedback queues, what is the advantage of using a different time
quantum in each queue?
Ans: Processes which need more frequent servicing, such as interactive processes, can be in a
queue with a small q. Processes that are computationally intensive can be in a queue with a
larger quantum, requiring fewer context switches to complete the processing, making more
efficient use of the CPU.
ii) On a System using multi level feedback queues, a totally CPU bound processes requires 100
seconds execute. If the first queue uses a time quantum of 10, and each lower level the time
quantum doubles, how many times will the job be interrupted and on what queue will it
terminate?
Ans:
Tq=10
Tq=20
Tq=40
Tq=80
On 4th queue process will terminate and will be interrupted 3 times.
iii)On a System using multi level feedback queues, a totally CPU bound processes requires 90
seconds to execute. If the first queue uses a time quantum of 7, and each lower level the time
quantum increases 5 time units, how many times will the job be interrupted and on what
queue will it terminate?
Ans:
Tq=7
Tq=12
Tq=17
Tq=22
Tq=27
Tq=32
Ans: On 6th queue process will terminate and will be interrupted 3 times.
Ques 6: We are given a computer system consisting of a CPU and a disk. We are told that each
user request has a compute time of 80 milliseconds and on average generates 10 disk
requests. We are further told that the service time at the disk is 10 ms.
a. Is this system compute bound or I/O bound?
b. What is the maximum number of user requests that can be satisfied per second?
c. If we are told that the disk is used 50% of the time, how many user requests are being
satisfied per second?
Ans:
a)System is I/O bound as CPU burst is quite smaller than I/O burst.
As in 100 ms(10*10),if we find the average CPU burst ,then it is 8ms.(Find why?)
b)A one User request consists of task which utilises CPU as well as I/O .
On an average,each user request takes total time=80ms+100ms=180ms
So in 180 ms,no of request satisfied =1
In 1ms ,no of request satisfied=1/180
In I sec, no of request satisfied=1000/180=5.5 =>5 user request maximum
c)
Disk is used 50% of the time.It means when a request comes ,request uses CPU for 80ms but
the disk for I/O is used only half of the time,ie 100/2=50ms.
=>now ,total time a 1 user request takes=80+50 =130ms.
So in 130 ms,no of request satisfied =1
In 1ms ,no of request satisfied=1/130
In I sec, no of request satisfied=1000/130=7.6 =>7user request maximum
Ques 7:
Consider a system running ten I/O-bound tasks and one CPU-bound task. Assume that the I/Obound tasks issue an I/O operation once for every millisecond of CPU computing and tha t 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
Ans:
• Since each I/O-bounded task issues an I/O operation every millisecond and it takes 10
milliseconds to complete, it definitely takes the overhead of context-switching every
millisecond.
The CPU-bounded task can’t finish within one time quantum, and takes the overhead of 0.1
millisecond of context-switching every millisecond as well. The execution sequence of CPU is
shown as the Gantt chart as below (each cell represents 1 millisecond of execution time,
except for the ‘o’ cells, which represent 0.1 millisecond of context-switching):
Therefore, regardless of the CPU-bounded or I/O-bounded tasks, the scheduler interrupts, and
processes a 0.1 millisecond of context-switching time consumption every millisecond. The CPU
utilization in this case is (just look at the first two rows of the scheduling because it’s the same
ratio in any larger scale):
a. CPU utilization of the tasks 1ms * 11 = 11ms
b. Every task will use up the whole quantum. The I/O operations for the I/O
bound tasks will return in time for their next turn. Only non utilizations will be
the context switch 11* .1 = 1.1ms
c. 1.1ms + 11ms = 12.1 total time.
d. 11/12.1 = .909, 90.9%
•
OR
Total time ( 1ms + .1ms )*10 + 10+.1 = 21.1
b. CPU utilization of CPU-bound task = 10ms
c. CPU utilization of I/O bound tasks = 1ms then context switch
d. 1*10 + 10 = 20ms total CPU utilization
e. 20/21.1 = .9478, 94.78%
Ques 8:Consider a 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),it’s priority changes at a rate of α ; when it is running, its
priority changes at a rate β. All processes are given a priority of 0 when they enter the ready
queue. The parameters α and β can be set to give many different scheduling algorithms
a. What is the algorithm that results from β > α > 0?
b. What is the algorithm that results from α < β < 0?
Ans:a) FCFS (First-come, first-served).
All the processes in the ready queue has the same inital priorty 0 (P 0 =0) . Their priority
increases at the same rate α (α >0). Once the process with the highest priority (first-come
compared to other process in the ready queue) is running, its priority increases at a higher
rate β > α > 0 than the priorities of those processes in the ready queue. So no other process
will preempt it and it will run to its completion.
b) LCFS (Last-come, first-served).
All the processes in the ready queue has the same initial priority 0 . Their priority decreases at
the same rate α (α <0).
The process say p1 with the highest priority is running.The priority of running process
decreases at greater rate β than process in the ready queue,at α(say of p2).So p2 will
preemept p1.P1 will come in ready queue.Now if a new process,p3 also arrive in ready queue
,it will have priority 0 .So running process p2 will be preempted by this new coming process
p3 because the new process's priority is 0 which is the highest possible priority. And so p3 will
pre-empt p2.Now say no new process comes so p3 will complete itself with no preemption.Then p2 will run and then p1.
Ques9:
Consider four CPU intensive processes which require 6, 3, 2, 1 time units and arrive at times 0,
0, 2 and 3 respectively. The priorities of the processes are 1, 3, 2 and 4 (lowest number
indicating highest priority).how many context switches are needed if the operating system
implements a preemptive priority scheduling algorithm? Do not count the context switches at
time zero and at the end?
Ans:
Arrival time
Cpu busrst
Priority
P1
0
6
1
P2
0
3
3
P3
2
2
2
P4
3
1
4
P1
0
P3
6
P2
8
P4
11
12
3 context switches.
Ques 10:
Consider three processes, all arriving at time zero, with total execution time of 20, 10, and 30
units respectively. Each process spends the first 10 % of execution time doing I/O, the next 80
% doing computation and the last 10 % of time doing I/O again.
The OS uses Shortest Remaining Time Next scheduling algorithm and schedules a new process
either when the running process gets blocked on I/O or when the running process finishes its
complete burst.
Assume that all I/O operations can be overlapped as muc h as possible that is you can assume
that there are many I/O devices present in the system. For what percentage of time CPU
remains idle?
Ans:
Process
P1
P2
P3
Arrival
time
Execution time
0
1
3
20
10
30
I/O TIME CPU
TIME
2
16
1
8
3
24
I/O TIME
2
1
3
Cpu idle time=(2+3)/53= 0.094 or 9.4%
Ques 11:
Give the completion time for the following processes when the scheduling algorithm is SRTF
and each process first spends some time on I/O, then on CPU and again on I/O.
Ans:
Process
P1
P2
P3
Gantt chart:
Arrival time
Execution time
0
1
3
I/O TIME
4
8
12
CPU TIME
14
28
42
I/O TIME
2
4
6
Completion
Time
20
50
94
Ques 13:
Given a system using SJF algorithm for Short term scheduling and exponential averaging with
α = 0.7, what would be the next expected burst time for a process with burst times of 5, 9, 3
and 5 and an initial value for Τ1 of 20?
Ans:
Ques 14:
On a system with n CPUs, what is the maximum number of processes that can be in the ready,
run and blocked states?
There is no limit to the number of ready and blocked processes.At most n processes can be
allocated to n cpu’s in this system,so n processes can be in run state at a time.
On a system with n CPUs, what is the minimum number of processes that can be in the ready,
run and blocked states?
There can be zero processes in any of 3 states.It is possible that all processes are in blocked
state waiting for I/O so no processes will be in ready and running state.
All processes can be in ready and running state,so no processes will be in blocked state.
Given a system with n processes, how many possible ways can those processes are scheduled?
Ans:It is like a cominatorics problem,which says in how many ways n objects(here n processes)
can be ordered in n places(here n CPUs).While we schedule first processes,for which we have
n choices.For each of the other process,we have n-1,n-2,….2,1 choices.
=>total no of ordering(schedules)= n * n-1 *n-2 * n-3 * ……3* 2 * 1=n!
For example ,for no. of processes=2(p1,p2) and for 2 CPUs(c1,c2)
Schedules are:
1)p1c1 p2c2 2)p1c2 p2c1
for no. of processes=3(p1,p2,p3) and for 3 CPUs(c1,c2,c3)
schedules are:
1)p1c1 p2c2 p3c3 2)p1c1 p2c3 p3c2 3)p2c1 p2c2 p3c3 4)p2c1 p1c3 p3c2 5)p3c1 p1c2
p2c3 6)p3c1 p1c3 p2c2
Describe the differences between Symmetric and Asymmetric multiprocessing? What are
three advantages and one disadvantage of multiprocessor systems?
Ans: Symmetric processing treats all processors as equals; I/O can be processed on any of
them. Asymmetric processing designates one CPU as the master, which is the only one
capable of performing I/O; the master distributes computational work among the other CPUs.
Some
advantages
of
multiprocessor
system
are
as
follows:
• Reduced Cost: Multiple processors share the same resources. Separate power supply or
mother
board
for
each
chip
is
not
required.
This
reduces
the
cost.
• Increased Reliability: The reliability of system is also increased. The failure of one processor
does not affect the other processors though it will slow down the machine. Several
mechanisms are required to achieve increased reliability. If a processor fails, a job running on
that processor also fails. The system must be able to reschedule the failed job or to alert the
user
that
the
job
was
not
successfully
completed.
• Increased Throughput: An increase in the number of processes completes the work in less
time. It is important to note that doubling the number of processors does not halve the time
to complete a job. It is due to the overhead in communication between processors and
contention for shared resources etc.
Disadvantages:
Multiprocessor systems are more complex in both hardware and software. Multiprocessing
system, however, require a very sophisticated operating system to schedule, balance, and
coordinate the input, output, and processing activities of multiple processors
v) Which scheduling algorithms require a Timer for the CPU?
Ans:Premptive scheduling algorithms like SRTF and Round robin require a Timer on the CPU
to allow the current process to be interrupted and allow the scheduler to either select the
next process to run from the ready queue or resume the currently running process(if the
quantum has not expired in case of RR and if there are no processes in the ready queue with
shorter remaing time as in case of SRTF)
Ques 15:
On a system using round robin scheduling, let s represent the time needed to perform a
process switch, q represent the round robin the time quantum and r rep resent the time a
process runs before blocking on I/O . Give a formula for cpu efficiency given the following:
a. q = ∞
b. q > r
c. s < q< r
d. s=q < r
e. q nearly zero
Ans: here s is actually the cpu burst of a process and q is the time quanta in RR.
a)In this case,each processes will run until they block i.e run for r units.For each cycle ,s unit of
overhead will be needed with r units of useful work.CPU efficiency=r/(r+s)
b) since processes will run until they block,so same answer as above
c)The no of context switches required =r/q
Time wasted in context switches=sr/q
CPU efficiency=r/(r+sr/q)=q/(q+s)
d) CPU efficiency=r/(r+sr/q)=q/(q+s)
now q=s
=>s/(s+s)=1/2
e) CPU efficiency=q/(q+s) (from part c)
q goes to 0
=> CPU efficiency goes to 0
Ques 16: Suppose that the following processes arrive for execution at the times
indicated. Each process will run for the amount of time listed. In
answering the questions, use nonpreemptive scheduling, and base all
decisions on the information you have at the time the decision must be
made.
Process Arrival Time
Burst Time
P1
0.0
8
P2
0.4
4
P3
1.0
1
a. What is the average turnaround time for these processes with the
FCFS scheduling algorithm?
P1
P2
P3
0.0
8
12 13
turnaround time for :
P1=8-0.0=8
P2=12-0.4=11.6
P3= 13 – 1.0 =12
Avg. turnaround time=(8+11.6+12)/3 = 10.53
b. What is the average turnaround time for these processes with the
SJF scheduling algorithm?
P1
P3
P2
0.0
8
9
13
turnaround time for :
P1=8-0.0=8
P2=13-1.0=12
P3= 9 – 0.4 =8.6
Avg. turnaround time=(8+12+8.6)/3 = 9.53
c. The SJF algorithm is supposed to improve performance, but notice
that we chose to run process P1 at time 0 because we did not know
that two shorter processes would arrive soon. Compute what the
average turnaround time will be if the CPU is left idle for the first
1 unit and then SJF scheduling is used. Remember that processes
P1 and P2 are waiting during this idle time, so their waiting time
may increase. This algorithm could be called future-knowledge
scheduling.
P3
P2
P1
0
1
2
6
14
turnaround time for :
P1=14-0.0=14
P2=6-0.4=5.6
P3=2-1.0 =1
Avg. turnaround time=(14+5.6+1)/3 = 6.86