0 ratings0% found this document useful (0 votes) 20 views9 pagesOperating System
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
a
Meci-dlii Senn
[An operating system is a construct that allows the user application programs to interact with the
system hardware, Since the operating system is such a complex structure, it should be created
with utmost care so it can be used and modified easily. An easy way to do this is to create the
operating system in parts, Each of these parts should be well defined with clear inputs, outputs
and functions.
ety" Ops a Sygten -L
Simple Structure
‘There are many operating systems that have a rather simple structure. These started as small
systems and rapidly expanded much further than their scope. A common example of this is MS-
DOS. It was designed simply for a niche amount for people. There was no indication that it
would become so popular.
‘An image to illustrate the structure of MS-DOS is as follows ~
Itis better that operating systems have a modular structure, unlike MS-DOS. That would lead to
greater control over the computer system and its various applications. The modular structure
Would also allow the programmers to hide information as required and implement internal
utipes aeihey see fit without changing the outer specifications.
ges
Structure
@ ‘One way to achieve modularity in the operating system is the layered approach. In this, the
bottom layer is the hardware and the topmost layer is the user interface.
‘An image demonstrating the layered approach is as follows ~
layers Uoey
woot, pp prctnw
Sef: Karna
Pord ware
vl
ee components
© scanned with OKEN Scanner6
AS seen from the ima,
i9e, each upper layer is built on the bottom layer. All the layers hide some
structures, operations
etc from their upper layers,
One problem with the layered structure is that each layer needs to be carefully defined. This is
necessary because the upper layers can only use the functionalities of the layers below them.
An operating system (OS) is basically a collection of software that manages computer hardware
resources and provides common services for computer programs. Operating system is a crucial
Component of the system software in a computer system
Batch Operating system is one of the important type of operating system.
The users who using a batch operating system do not interact with the computer directly. Each
user prepares its job on an off-line device like punch cards and submits it to the computer
Operator. To speed up the processing, jobs with similar needs are batched together and run as.
@ group. The programmers exit their programs with the operator and the operator then sorts the
programs with similar requirements into batches.
‘The problems that occurs with Batch Systems are as follows ~
‘+ There is a lack of interaction between the user and the job.
+ CPUis being often idle, because the speed of the mechanical /O devices is slower than
the CPU.
+ _Itis difficult to provide the desired priority.
‘An operating system (OS) is basically a collection of software that manages computer hardware
Tesources and provides common services for computer programs. Operating system is a crucial
Component of the system software in a computer system.
Distributed Operating System is one of the important type of operating system.
Multiple central processors are used by Distributed systems to serve multiple real-time
applications and multiple users. Accordingly, Data processing jobs are distributed among the
processors.
Processors communicate with each other through various communication lines (like high-speed
buses or telephone lines). These are known as loosely coupled systems or distributed
systems. Processors in this system may vary in size and function. They are referred as sites,
nodes, computers, and so on.
Advantages
+ With resource sharing facility, a user at one site may be able to use the resources
available at another.
+ Speedup the exchange of data with one another via electronic mail
+ Failure of one site in a distributed system doesn't affect the others, the remaining
can potentially continue operating
+ Better service to the customers.
+ Reduction of the load on the host computer.
+ Reduction of delays in data processing
CPU scheduling is a process that allows one process to use the CPU while the execution of
another process is on hold(in waiting state) due to unavailability of any resource like I/O etc,
thereby making full use of CPU. The aim of CPU scheduling is to make the system efficient,
fast, and fair.
Whenever the CPU becomes idle, the operating system must select one of the processes in
the ready queue to be executed. The selection process is carried out by the short-term
scheduler (or CPU scheduler). The scheduler selects from among the processes in memory that
are ready to execute and allocates the CPU to one of them
© scanned with OKEN ScannerCPU Scheduling: Dispatcher
Another component involved in the CPU scheduling function is the Dispatcher. The dispatcher
is the module that gives control of the CPU to the process selected by the short-term
scheduler. This function involves:
= Switching context
+ Switching to user mode:
‘+ Jumping to the proper location in the user program to restart that program from where it left last
time.
‘The dispatcher should be as fast as possible, given that itis invoked during every process
switch. The time taken by the dispatcher to stop one process and start another process is
known as the Dispatch Latency. Dispatch Latency can be explained using the below figure:
event response to event
response interval i
process made |
interrupt available leatstime process,
_Processing_ execution |
|
dispatch
|
conflicts dispatch |
| |
time
a
©
Types of CPU Scheduling
CPU scheduling decisions may take place under the following four circumstances
4. When a process switches from the running state to the waiting state(for /O request or
invocation of wait for the termination of one of the child processes).
2. When a process switches from the running state to the ready state (for example, when
an interrupt occurs).
3. When a process switches from the waiting state to the ready state(for example,
completion of V/0).
© scanned with OKEN Scanner4 When a process terminates:
WH AKuTKANs | and 4 there is no choice in tems of scheduling, A new process(if one exists
INH ANAL Quove) Must bo selected for evecution, There is a choice, however in
SerumRanes 2 and &
WS SPasning takes place only under circumstances 1 and 4, we say the scheduling
SHore § Non-Preemptive! othentise, the scheduling scheme is preemptive.
Non-Preemptive Scheduling
Under nongeematve schesk
seers he CFU
—
12, once the CPU has been allocated to a process, the process
releases the CPU either by terminating or by switching to the waiting
Ths sesing met
SEEING ATES
S used by the Microsoft Windows 3.1 and by the Apple Macintosh
2S DS ony Meshes thst can be used on certain hardware platforms because It does not require
‘DS SQenS! Nereis" for example a timer) needed for preemptive scheduling,
inagtersematke schesu! Sos not intemupt a process running CPU in the middle of the
SxSRTON HStsSS_ TSS HT the process completes its CPU burst time, and then after that it
Figure: Non-Preemptive Scheduling
© scanned with OKEN Scanner, —_ — —
Preemptive Scheduling
In this type of Scheduling, the tasks are usually assigned with priorities. At times it is necessary
to run a certain task that has a higher priority before another task although it is running,
Therefore, the running task is interrupted for some time and resumed later when the priority task
has finished its execution,
Thus this type of scheduling is used mainly when a process switches either from running state
to ready state or from waiting state to ready state. The resources (that is CPU cycles) are
mainly allocated to the process for a limited amount of time and then are taken away, and after
that, the process is again placed back in the ready queue in the case if that process still has a
CPU burst time remaining, That process stays in the ready queue until it gets the next chance to
execute.
‘Some Algorithms that are based on preemptive scheduling are Round Robin Scheduling (RR),
Shortest Remaining Time First (SRTF), Priority (preemptive version) Scheduling, etc.
z= SSE 1
Figure: Preemptive Scheduling
CPU Scheduling: Scheduling Criteria
There are many different criteria to check when considering the "best" scheduling algorithm,
they are:
CPU Utilization
To make out the best use of the CPU and not to waste any CPU cycle, the CPU would be
working most of the time(Ideally 100% of the time). Considering a real system, CPU usage
should range from 40% (lightly loaded) to 80% (heavily loaded.)
© scanned with OKEN ScannerThroughput
It 6 tha {otal numbor of processes comploted por unit of time or rather says the total amount of
work done in a unit of time. This may range from 10/secand to 1/hour depending on the specific
processes,
Turnaround Time
ILis the amount of time taken to execute a particular process, i.¢. The interval from the time of
‘submission of the process to the time of completion of the process(Wall clock time).
Waiting Time
The suum of the periods spent waiting in the ready quoue amount of time a process has been
wailing in the ready queue to acquire get control on the CPU.
Load Average
1Nis the average number of processes residing in the ready queue waiting for their turn to get
into the CPU
Response Time
Amount of time it takes from when a request was submitted until the first response is produced,
Remember, it is the time till the first response and not the completion of process execution(final
response)
In general CPU utilization and Throughput are mayimized and other factors are reduced for
proper optimization.
Scheduling Algorithms
To decide which process to execute first and which process to execute last to achieve maximum
CPU utilization, computer scientists have defined some algorithms, they are:
First Come Furst Serva(FCFS) Scheduling
5 Job-Firei(SJF) Scheduling
Priority Scheduling
Rabin(RR) Scheduling
Multilevel Queue Scheduling
Multilevel Feedback Que eeduling
Shortest Remaining Time First (SRTF)
Longest Remaining Time First (LRTF)
Highest Response Ratio Next (HRRN)
We vill be discussing all the scheduling algorithms, one by one, in detail in the next tutorials.
‘A deadlock happens in operating system when two or more processes need some resource to
complete their execution that is held by the other process.
S@ernourena
© scanned with OKEN Scanner>| Process
_ |
ae
Resource 1 Resource 2
— =
process 2
Deadlock in Operating System
In the above diagram, the process 1 has resource 1 and needs to acquire resource 2. Similarly
process 2 has resource 2 and needs to acquire resource 1. Process 1 and process 2 are in
deadlock as each of them needs the other's resource to complete their execution but neither of
them is willing to relinquish their resources.
Coffman Conditions
‘A deadlock occurs if the four Coffman conditions hold true. But these conditions are not
mutually exclusive.
‘The Coffman conditions are given as follows ~
Mutual Exclusion
‘There should be a resource that can only be held by one process at a time. In the
diagram below, there is a single instance of Resource 1 and it is held by Process 1 only.
Allocated
Process 1
Resource 1
Hold and Wait
A process can hold multiple resources and still request more resources from other
processes which are holding them. In the diagram given below, Process 2 holds
Resource 2 and Resource 3 and is requesting the Resource 1 which is held by Process
1
© scanned with OKEN ScannerAllocated
Wocated | Resource 2
Allocated Request
| Resourcer feP2* | process 2 a
Pro =)
Atioeates
Resource 2
No Preemption
A resource cannot be preempted from a process by force. A process can only release 2
resource voluntarily. In the diagram below, Process 2 cannot preempt Resource 1 from
Process 1. It will only be released when Process 1 relinquishes it voluntarily after its
‘execution is complete.
Allocated Request auisstes | pesource 2
Process 1 }#—~"—"""}_ Resource 1 Process 2
Circular Wait
A process is waiting for the resource held by the second process, which is waiting for the
resource held by the third process and so on, till the last process is waiting for a
resource held by the first process. This forms a circular chain. For example: Process 1 is
allocated Resource? and it is requesting Resource 1. Similarly, Process 2 is allocated
Resource 1 and itis requesting Resource 2. This forms a circular wait loop.
© scanned with OKEN ScannerDeadlock Detection
A deadlock can
ig aiiseatedl ia enero by a resource scheduler as it keeps track of all the resources that
are alocaled to diferent processes, Alera deatock is detected, can be resolved using the
+ Allthe processes that are involved in the deadlock are terminated. This is not a good
approach as all the progress made by the processes is destroyed
+ Resources can be preempted from some processes and given to others til the deadlock
is resolved.
Deadlock Prevention
‘an occur, So, the system checks each
It is very important to prevent a deadlock before it
transaction before it ig executed to make sure it does not lead to deadlock. I there is even a
slight chance that a transaction may lead to deadlock in the future, it is never allowed to
execute. Deadlock Avoidance
Itig better to avoid a deadlock rather than take measures after the deadlock has occurred, The
wait for graph can be used for deadlock avoidance. This is however only useful for smaller
databases as it can get quite complex in larger databases.
Types of CPU scheduling Algorithm
There are mainly six types of process scheduling algorithms
First Come First Serve (FCFS)
Shortest-Job-First (SJF) Scheduling
Shortest Remaining Time
Priority Scheduling
Round Robin Scheduling
Multilevel Queue Scheduling
POrONa
Scheduling Algorithms
© scanned with OKEN Scanner