Operating system and unix
What is operating
system
·
Whatever used as on interface blw the user
and the care nachine is operating system
Why we need operating
system
·
To enable everybody to use h/w in a canverient and efficient manner
·
A program or system s/w which acts as an interacliery between users and
h/w
1. Galvin
2. Stalling
Operating
system is a rescurce manager / allocator
·
Manage system resources in unbuyest fashion both h/w and s/w
CPU , I/o
stroge and provide functionality to an application program .
Abstract
view of computer system
·
Operating system provides platform on which other application
software can be instslled .
·
Provides the environment within which programs are executed
Abstract view of system component
Evolation of operating system
· Early computer’s were not interactive device there user use to prepare a job which consist three parts .
1.
Program
2.
Control information
3.
Inputdata
Program :-
Ø Only one job is given input at a
time as there was no memory , computer will take the input then process it and
then generate output .
Ø Common input/output device were punch card .
Ø So these device were very slow and process remained ideal at the time
Btch operating system
Ø
To speed up the processing
job with similar types ( programming language ) were batched together and were
ran through the processor as a group ( Batch )
Ø
In some system grouping is
done by the operater while in same system it is pergrmed by the batch
monitor
Ø
Then jobs ( As a group punch
cards ) are bunlen into batches with similar requirements (Advantage )
Advantage :-
·
The batched jobs were
executed automatically one after another saving its time by performing the
activities ( like loudening compiler ) only for once .
·
It resuttedin improsel
system untilization are to reduced
trrnaronel time.
Disadvantage
·
Memory limitation :- Memory
was very limited because of which instructive process or multiprogramming was
not possible.
Multiprogramming
operating system
Several jobs are kept in main memory at the same time
and cpu is multiplexed among them.
Example : - To
process p1 and p2 with cpu and i/o bursts of one unit time each.
1. A Single program can not in
general keep either the cpu or the i/o devices busy at all times.
2. The basic idea of
multiprogramming operating system is it keops seueral jobs in main memory at
the same time.
3. The jobs are keit initially
on the hard disk in the job pull this consistent of all process residing on
disk awaieting allocation of main memory.
Advantage
·
Hign and efficient cpu utilization less response time or
waiting.
·
Several process share cpu time
Disadvantage
·
It is difficult to program a system because of complicated
schedule handling.
· To accommodate many jobs in main memory , complex memory management is required.
👦
Multi Tasking OS/ Time sharing/Fair Share OS
· · In the morden operating system we are able to play mp3 music ,all running at the same time.
· · For multitasking to take place firstly there should be multiprogramming presence of multiple programs read for execution and secondly the concepts of time sharing.
Multiprocessing
operating system
· · Multiprocessor os refers to use off two or more CPUs within a single computer system . these multiple CPUs are in a close communication sharing the computer bus memory and i/o device . The system are referred as tightly coupled system .
Multiprocessing
OS
1. Symmetric
2. Asymmetric
Symmetric :-
· · In a symmetric multi-processing a single od controls two or more identical processors connected to a single man memory
Asymmetric
:-
· · This scheme defines a master salve relationship where 1 processor behaves as a master and controls another processor which behave as slaves.
REAL TIME OPERATING SYSTEM
· A system that produce output for given input within a well – defined time
period , else the output is useless.
· Often
used a control device such as medical , nuclear plant, rocket launch etc.
Hard Real Time OS:- This is also a type of OS and it is predicted
by deadline.There predicted deadline will react at a time
t=0.
Example :- Hospital ICU,
Soft Real Time OS :- The soft real time OS has certain deadlines
that may be missed and they will take action at time
t = 0+.
● The critical time of this os is
delayed to some extent.
Example:- phone call
Process Management
Process:- In general ,a process is a program
in execution .
● A Program is not a process by default.
● A program is a passive entity ,i.e a file
instruction stored on disk.
● A program becomes a process when an
executable file is loaded into main memory (RAM) and when its
PCB(Process Control Block) is created.
● A process on the other hand is an active
entity .which requires resources like main memory, cpu
time, register, system bus.
-:A process consists of following sections:-
● Text Section :- Also known as program code.
● Stack section :- which contains the
temporary data(function parameters, return address and local variable)
● Data Section :- Containing Global variables.
● Heap section :- which is memory dynamically
allocated during process run time .
Process Control Block(PCB)
● Each process is represented in os by a
process control block which is also called task control block.
● PCB simply serves as the repository for any
information that may vary from process to Process it
contains many pieces of information associated with a
particular .
● Process States :- the state may be new or
running , waiting so on.
● Program Counter:- the next counter indicates
the address of the next instruction to be executed for
this process. It is a type of register.
● Process States :- A process changes states
as it is executed. The state of process is defined in
parts by the current activity of the process . A process may
be one of the
following states:
● New :
The
process is being created .
● Running:
Instructions
are being executed .
● Waiting
(Block): The process is waiting for some event to occur such as i/o completion and other events.
● Ready
: The
process is waiting to be assigned to the processor or cpu.
● Terminated
: The
process has finished execution.
Schedulers
● Schedulers : A process migrates among the various scheduling queues throughout its life cycle. The operating system must select the scheduling process in the same fashion ,the selection process is carried out by the appropriate scheduler .
Queueing Diagram of process scheduling
Types
of Schedulers
1. Short
Term Scheduler(STS) : The short term scheduler also known as, CPU Scheduler ,selects from among the processes
that are ready to execute and allocate the cpu to one of
them.
Short
Term Scheduler(STS) : select which process should be executed next and allocate it to the CPU through
dispatcher.
● Short Term Scheduler is invoked(called) very frequently.
● It is invoked when following events.
1. CPU Slice of the current process finished.
2. Current process needs to wait for an event.
3. I/O interrupt.
4. System Call.
5. Signal.
CPU
Bound and I/o Bound Process
I/O
Bound Process : An I/O bound process is one that spends more of its time doing I/O than it spends doing
computation.
CPU
Bound Process : A CPU Bond process generates I/O requests infrequently using more of its time doing
computation.
Note:-
It is
important that long term schedulers select a good process mix of I/O Bond and CPU Bond .
2. Long
Term Scheduler(Spooler) : Select process from the job pool to bought into the ready queue.
● Long term Scheduler is invoked very infrequently
● Long Term Scheduler controls the degree of multiprogramming.
Degree
of Multiprogramming : The number of processes in memory is known as Degree of multiprogramming.
● If the degree of multiprogramming then the Average
Rate of Process creation must be equal to the average rate of
process leaving the system .
So, This means the long term scheduler may need to
invoke only
when the process leaves the system.
3. Medium Term Scheduler(swaper) :
● It is also Known as swaper .
● It selects an in-memory process and swaps it out to the disk temporarily .
● Swapping decision is based on several factors.
1. Arrival of a higher priority process but no memory available ,
2. Poor mix of jobs.
Dispatcher : The Dispatcher is the module that gives control of the CPU to the process selected by the short-term scheduler.
● The Dispatcher should be as fast as possible since it is invoked during every process switch.
Context Switch: When the CPU switches to another process ,the system must save the state(context) of the current process and load the states for the new process .
● Context switch time is overhead, the system does no useful work while switching .
CPU
Scheduling Type
of scheduling :-
1. Non- preemptive
2. Preemptive
Non Preemptive :- Under non preemptive scheduling once the cpu has been allocated to a process ,the process keeps the cpu until it releases the cpu wilingley
● A process will leave the cpu .
1. When a process completes its execution(terminate states)
2. When a process wants to perform some i/o operation
Preemptive :- Under preemptive scheduling once the CPU allocated to a process will leave the CPU or it can be forced to leave the CPU .
● Process will leave the CPU when .
1. When a process is complete it is executed.
2. A new process enters in the ready quqe/ready state (new/waiting ),in case of High priority.
3. When a process leaves CPU to perform forcefully
4. When the process switches from running to ready
state because of time quantum expires.
Scheduling
criteria
1. CPU
utilization : Keep the cpu as busy as possible.
2. Throughput : number of processes that complete their execution per unit time.
3. Turn around time : Amount of time to execute a particular process.
4. Waiting time : Amount of time a process waits in the ready queue .
5. Response time : is the time it takes to start responding, not the time it takes the output response
Note : the CPU-scheduling algorithm does not affect the amount of time during which a process executes I/O , It affects only the amount of time that a process spends waiting in the ready queue.
● It is desirable to maximize CPU utilization and throughput and to minimize turnaround time, waiting time and response time.
Scheduling
Algorithms
1. FCFS(First
Come First Serve) : The process that enters the ready queue First is scheduled First regardless of the
size of its next CPU burst.
➔ FCFS is the simplest scheduling algorithm as the name suggests the process that requests the CPU first is
allocated the CPU first .
➔ Implemented by FIFO Queue
.
➔ It is always Non
preemptive in nature
Average Waiting Time = 3+2+0+6+6/5 = 3.4
Turn
Around Time = 7+4+3+8+7/5 = 5.8
Advantage
of FCFS:-
● Easy to understand and easy to implement using queue
data structure .
● Can be used for background processes where execution
is not urgent.
Average Waiting Time = 0 + 99 / 2 = 49.5
Turn Around Time = 100 + 101 / 2 = 100.5
Average Waiting Time = 1 + 0 / 2 = 0.5
Turn Around Time = 101 + 2 / 2 = 51
Convoy effect
● If the smaller process has to wait more the cpu
because of the larger process then this effect is called convoy
effect ,it results in more average writing time.
Solution:- smaller processes have to be executed before longer processes, to achieve less average waiting time.
FCFS
Disadvantage● Suffer from convoy effect.
● Higher average waiting time TAT compare to other algorithm.
● The FCFS algorithm is troublesome for time sharing system (due to its non-preemptive nature)
Shortest Job First(SJF)
➔ Process with the shortest
cpu burst is scheduled first.
➔ Whenever we make a
decision of selecting the next process for CPU execution ,out of all available processes, CPU
is assigned to the process having the smallest burst
time.
➔ When the CPU is available,
It is assigned to the process that has the smallest next CPU Burst.
➔ If there is a tie FCFS is
used to break ties.
➔ It supports both non
preemptive and preemptive(greedy approach)
➔ In SJF (non preemptive )
once a decision is made and among all the available process , the process with the
smallest CPU burst is scheduled on the CPU , it can not be
preemptive even
if a new process with the smaller CPU burst
requirement then the remaining CPU burst of the memory process enter in
the system .
Average waiting time = 3+10+0+7/4 = 5
Average TAT = 5 +14+6+11/4 =9
SRTF(Preemptive) = Shortest Remaining Time First.
➔ In shortest remaining time
first(SRTF) preemptive:
➔ Whenever a process enters
in ready state, again we need to make scheduling decisions whether this new process
with the smaller cpu burst requirement then the remaining cpu
burst of
the running process and if it is the case then the
running process preempts and new process is scheduled on the
CPU.
Q1 :- SRTF
Average waiting time = 9+1+0+2/4 = 3
Average TAT = 16+5+1+6/4 = 7
Q2:- SRTF
Average waiting time = 7+3/4 = 2.5
Average TAT =12+3+6+1/4 = 5.5
Advantages
of SJF
● Preemptive version guarantees minimum average
waiting time, so it is sometimes also referred to as the
optimal algorithm.
● Provides a standard for other algorithms in terms of
average waiting time.
● Provide better average response time compared to
FCFS.