You are on page 1of 5

University of Sargodha

Computer Science and Information Technology


Paper B – For Even Roll Number Students
MIDTERM EXAM
INSTRUCTOR: Naveed Ahmad
SUBJECT: Operating System CLASS: MSc IT 2nd Self
TIME ALLOWED: 1-week MARKS: 30
Student Name Adnan Ahmed Student Roll No. MITF19E050

Instructions
1. Don’t copy data from internet, you may take concept and then type in your own words.
2. Don’t copy from your class fellow because plagiarism will be checked and you will get NO
CREDIT if data is copied.
3. Viva will be conducted on the completion of the paper, so be prepared conceptually about
what you type here in your paper.
4. Write your answers in the given space of this paper sheet, for question 1 you may add
more rows to add more terms.

Question 1: Watch all video lectures on OS (three lectures per day, my suggestion) and discuss the
topic covered in the lecture in your own words, no practical examples are needed,
only cover the theoretical portion. Don’t copy from the internet or from your class
fellow. Viva will be also conducted for this question. [MARKS: 10+6 = 16]

Link to OS Playlist:
https://www.youtube.com/playlist?list=PLuBM8LkREOp97J-DYarKohCaJbpKaMQOJ

Lecture Description
Lecture 1 1) Operating System 2) Booting
Operating System:
Operating system is a collection of program which is used to run hardware. It
responsible for taking care of all the hardware and managing the applications
access to the hardware. It acts as a manager of all the hardware in the system.
Booting:
Booting is the procedure of loading the operating system when the computer is
turned on. It has five steps.

Lecture 2 1) Process 2 Process Attributes in Operating Systems


Process:
The program that is in running state is known as process. When the program is
fully loaded into memory then the process is an active entity. When executable
files stored on hard drive the program is a passive entity.
Process Attributes:
Text Section: The code written into the program is referred to as text section.
Data Section: The variables used in the program are referred to as the data
section.
Heap: it is used for memory allocation. Also it is adjustable
Stack: it is a memory in which we get data in reverse order .i .e LIFO.
Program Counter: it is part of the process that holds the address of upcoming
instruction.
Lecture 3 1) Process State
When the process executes, it change its state.
New: The process is about to create.
Ready: After creation, the process is ready to run.
Running: The process in execution. It means the process is allocated to CPU.
Terminated: The process finish its execution.
Waiting: The process is waiting to proceed i/o request. It is also known as
blocked state.

Lecture 4 1) Scheduling Queues


There are 3 types of scheduling queues in operating system.
a) Job queue:
All the processes which are in the system are in job queue.
b) Ready queue:
List of processes that are in main memory and waiting for executing.
c) Device queue:
List of processes that are waiting for any input/output device.

Lecture 5 1) Scheduler:
3 types of schedulers:
a) Short term scheduler:
It is responsible for scheduling one of the process from ready state to
running state.
b) Medium term scheduler:
It is responsible of suspending and resuming the processes. It is also
swapper.
c) Long term scheduler (Job scheduler):
Long term scheduler is responsible for creating new processes and bringing
them into the system.

Lecture 6
Lecture 7
Lecture 8 1) CPU Scheduling 2) Criteria to check Best Algorithm.
CPU Scheduling:
Picking the process from ready state and give it to CPU with the help of CPU
scheduler is known as CPU scheduling.
There are several CPU scheduling algorithms:
FCSS, SJF, SRTF, Priority Scheduling, round robin,multilevel queue, Multilevel
feedback queue.
Criteria to check Best Algorithm:
 CPU Utilization: Keep the CPU busy. It must be high.
 Throughput: How many process completed in a unit time. It must be high.
 Waiting Time: waiting for some i/o device. Turnaround time – burst time =
waiting time. It must be low.
 Response Time: After arrival of process, the first time that process gets the CPU.
It must be low.
 Turnaround Time: The Time from the start of the process to its completion. It
must be low.
Lecture 9 1) First Come First Serve 2) Convoy Effect
First Come First Serve:
Assign CPU to process which comes first as the name
suggest first come first serve.
There are two types of CPU scheduling: Pre-emptive & non-pre-emptive.
Pre-emptive: if the process is running in the CPU then that process can be
forcefully remove from the CPU and CPU can be allocated to another process.
Non-pre-emptive: Once a CPU is allocated to one process then that process
cannot removed from CPU until termination.
Lecture 10 1) First Come First Serve

Lecture 11 1) Shortest Job First Scheduling (SJF) :


In Shortest Job First Scheduling: all the processes which are in waiting state, it
selects the process having shortest burst time. CPU allocated to that process
and it continues its execution until termination. We cannot remove the process
from CPU in between the execution of that process. If two process with same
burst time then we apply FIRST COME FIRST SERVE to break time.
Lecture 12 1) Shortest Remaining Time First (SRTF) Scheduling:
In SRTF scheduling algorithm, if newly-arrived process us having shortest bursts
time then remaining first time of the currently running process. After that you
will remove currently running process and allocate the CPU to the newly-arrived
process and the currently running process will wait in the ready queue.
Lecture 13 1) Non-preemptive Scheduling:
In priority scheduling algorithm, each process has its own priority. Also out of all
the available processes (processes which are in ready queue now) highest
priority process gets the CPU. If two processes having same priority then you
use FIRST COME FIRST SERVE to break the tie. Also If arrival time is also same
then we consider the order of process (p1,p2 and p3 etc ).
Lecture 14 1) Pre-emptive Scheduling:
In pre-emptive scheduling algorithm, one process is running and at some point
of time another process will come having higher priority then the process which
is running, the operating system pre-empt the CPU and allocation to that new
process which has higher priority.
Lecture 15 2) Round Robin Scheduling:
In Round Robin Scheduling algorithm, we schedule the process within fixed time
quantum . This scheduling algorithm is similar to First Come First Serve But with
some Time Quantum. Time quantum is period for which process is allow to run
uninterrepted. The criteria of this algorithm is arrival time and time quantum.
We pick one process which has been arrived in the ready queue. CPU will
allocated to that process, that process will continue its execution till time
quantum expires. It is always pre-emptive. The advantage of this scheduling
algorithm is that it gives deterministic response time to every process. In case of
averge response time it is one of best algorithm.

Lecture 16
Lecture 17
Lecture 18 1) Multilevel queue scheduling
In multilevel queue scheduling algorithm, There are multilevel of queues and
each has its own scheduling algorithm. These queues has also following fixed
priority scheduling algorithm in which one has Top priority and other has
medium and lower priority. If a process assigned to a particular queue during its
execution till its termination, that process cannot change its queue or cannot
migrate to another queue. In other words we can say when a process came, it is
permanently assigned to particular queue.
The problem in this algorithm is STARVATION in which the processes from last
queues should wait for long or for infinite time.
Lecture 19 1) Multilevel Feedback queue scheduling
In multilevel feedback queue scheduling, The queue from lower priority can be
promoted to a queue having higher priority. Also higher priority queue can be
demoted to the processes to the queue having lower priority.
Lecture 20 1) Process Synchronization:
In process synchronization, Processes must be synchronized. Processes can be
executed one by one which means when one process executing, no other
process can executed until first one termination. i.e ATM. Process
synchronization cooperative processes k darmeyan mn hoti ha.
Race condition: The scenario or condition in which multiple processes can use a
shared resource.
Critical Section: The resourse which is shared.
Lecture 21 1) Solution of the critical problem:
a) Software Based Solution b) Hardware Solution c) OS System Based System
Every Solution have four parts: Entry Section, Critical Section, Exit Section and
Remainder Section.
Entry Section: it checks the process who should go and who should not to
critical section. It also sure that there is no already existing process in critical
section.
Critical Section: The resourse or variable which shared among all processes.
Exit Section: it tells that it finishes task from critical section.

Lecture 22
Lecture 23
Lecture 24
Lecture 25

Question 2: Write a program in C++ programming language to implement Shortest Remaining


Time First (SRTF) scheduling algorithm. [MARKS: 10+4 = 14]

Input: This program should get the number of processes, arrival time and
burst time from the user.

Output: This program should provide the Gantt Chart, Average Arrival Time
and Average Turnaround Time.

The interface of the program must be as following:

Enter the number of process: 4


Enter Arrival Time for: -
P1: 0
P2: 5
P3: 1
P4: 7
Enter Burst Time for: -
P1: 25
P2: 15
P3: 5
P4: 5

Then show Gantt Chart


Then show Average Waiting Time
Then show Average Turnaround Time
Answer:

You might also like