You are on page 1of 4

Ahmadu Bello University Zaria

Department of Computer Science


First Semester 2018/2019 Academic Session
COSC 801: Operating System Assignment
REG: P18PSCS8037

Question One: Preliminaries, Operating System Structure and Properties


a) Give two principal reasons why a course on operating system is practical

A course in operating systems is practical for the following reasons


 As a computer scientist, it is practical because you will interface with them, whatever you are a
programmer, system administrator, etc An understanding of what goes on inside an operating
system will allow you to be more effective in any field of computer science.

 Operating systems provide the classic application domain for certain techniques that are useful in
other contexts. For example resource allocation; Security; and fault tolerance are all topics that are
traditionally thought of as “operating system” topics that now have broad applicability

b) What are the goals of Operating Systems?


i) Efficient use of a Computer System
ii) User convenience
iii) manages main memory
iv) manages processor
v) manages device and file system manipulation

c) Define the essential properties of the following Operating Systems


a. Handheld Systems: In handheld systems, the OS is designed to manage memory
efficiently and not to task the slow processor because they generally have small memory
and slow processor. Familiar tasks such as reading email or browsing web pages must be
condensed in order to fit the smaller display that come with these devices.

b. Networked Systems: In networked systems, the OS provides environment in where


users, can access remote resources by either logging into appropriate remote machine or
transferring data from the remote machine to their own machine

c. Real Time Systems: the system reads information from sensors and must respond within
a fixed amount of time to ensure correct performance

d. Distributed Systems: This system distributes computation among several physical


processors. The processors do not share memory or a clock. Instead, each processor has
its own local memory. They communicate with each other through various communication
lines, such as a high-speed bus or telephone line.

d) Differentiate between synchronous and asynchronous I/O structures


In synchronous I/O, a thread starts an I/O operation and immediately enters into a wait
state until the I/O request is completed. Whereas,
Asynchronous I/O, a thread sends I/O request to the kernel by calling an appropriate
function. If the request is accepted by the kernel, the calling thread continues processing

P18PSCS8037
another job until the kernel signals to the thread that the I/O operation is complete. It
then interrupts its current job and process the data from the I/O operation.

e) State three things you like and two that you do not like about this course
Three (3) Likes
 It is a practical course. The user gets to operate the system due to user friendly
interface
 It provides for convenient usage of the system such as memory management.
 Without the operating system, the user and hardware as components of the
operating system cannot function.

Two (2) Dislikes


 Operating system is wide and reasonably complex
 For the fact that deadlock is treated as an operating system topic, some current
operating systems can still not avoid and prevent deadlock from occurring

Question Two: Process Synchronizations


a) What is race-condition? Give an example.

A race condition is an undesirable situation that occurs when a device or system


attempts to perform two or more operations at the same time, but because of the
nature of the device or system, the operations must be done in the proper sequence
to be done correctly.
A simple example of a race condition is a light switch. In some homes there are
multiple light switches connected to a common ceiling light. When these types of
circuits are used, the switch position becomes irrelevant. If the light is on, moving
either switch from its current position turns the light off. Similarly, if the light is off,
then moving either switch from its current position turns the light on. With that in
mind, imagine what might happen if two people tried to turn on the light using two
different switches at exactly the same time. One instruction might cancel the other
or the two actions might trip the circuit breaker.

b) Show how TestAndSet can be used to solve the critical section problem Boolean

TestAndSet(boolean *target) {
boolean rv = *target;
*target = TRUE;
return rv;
}

P18PSCS8037
Solution

do {
while (TestAndSetLock(&Lock))
// do nothing
// Critical section
Lock = FALSE;
// remainder section
} while (TRUE);

Question Three: CPU Scheduling


a) What (if any) relation holds between the following pairs of sets of scheduling algorithms?
i. Priority and SJF: Both scheduling algorithms can be pre-emptive and non-preemptive.
The CPU is assigned to the process with highest priority. In SJF, priority is based on
process with the smallest burst time, while in priority, a priority number is assigned to the
process.
ii. FCFS and RR: First Come First Served is similar to Round Robbin in that, both
scheduling algorithms assign the CPU to process that arrived first or requests the CPU
first.

b) 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

i. Draw Gantt Charts illustrating the execution of these processes using a non-preemptive priority
(a smaller priority number implies a higher priority), and Round Robin (quantum = 1) scheduling.
Non-pre-emptive priority
P2 P5 P1 P3 P4
a. 1 6 16 18 19

Round Robbin (Quantum = 1)

9 0 1 0 4 8 0 3 7 2 6 1 5 0 4 3 2 1 0
P1 P2 P3 P4 P5 P1 P3 P5 P1 P5 P1 P5 P1 P5 P1 P1 P1 P1 P1

b. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

ii. What is the average turnaround time of each process for each of the scheduling
algorithm in i?
The Average turnaround time for Non-pre-emptive priority
P2= 1; P5= 6; P1= 16; P3= 18; P4= 19

P18PSCS8037
The Average turnaround time for Round Robbin (Quantum = 1)
P1= 19; P2= 2; P3= 7; P4= 4; P5= 14

c) Suppose that the same processes arrive for execution at the times indicated below but with the
same burst time as given in b) above.
Process Burst Time Arrival Time
P1 10 0.0
P2 1 0.5
P3 2 1.0
P4 1 1.2
P5 5 1.5

i. Draw Gantt Charts illustrating the execution of these processes using FCFS and SJF
non-preemptive scheduling

Gantt Chart for FCFS


P1 P2 P3 P4 P5
0 10 11 13 14 19

Gantt Chart for Shortest Job First Non pre-emptive


P1 P2 P4 P3 P5
0 10 11 12 14 19

ii. Which of the schedules in i) results in the minimal average waiting time (over all
processes)?

Average waiting time FCSF:

P1= 0; P2= 10-0.5= 9.5; P3= 11-1.0= 10; P4= 13-1.2= 11.8; P5= 14-1.5= 12.5

Average waiting time SJF:

P1= 0; P2= 10-0.5= 9.5; P3= 12-1= 11; P4= 11-1.2= 9.8; P5= 14-1.5= 12.5

Shortest Job First has the minimal average waiting time with average waiting time of 8.56
milliseconds.

P18PSCS8037

You might also like