Operating System
Operating System
Muhammad Tauqeer
Operating System
Operating system is system software
It work as a interface b/w user and hardware
Interaction between user and hardware is provided by Operating Sytem
Why OS?
User access to hardware without OS is difficult
Without OS the user can write their own program for any hardware they want to access
OS is used to access hardware to the user they want to access easily
Operating System Goals
Jobs scheduling
If several jobs are waiting to be brought in the memory and there is no enough space then
CPU select jobs among them which is know as scheduling
Multitasking Operating Systems (Preemptive)
Extension of multiprogramming
Uses multiprogramming and CPU scheduling to provide portion of time to each user
CPU executes multiple jobs by switching among them typically assigned some specific
quantum of time for which process is to be executed.
This switching occurs so fast that user feel like interacting with each executing task at the
same time.
Multiprocessing Operating Systems
More than one processor is used.
Allow more than one process to be executed at the same time.
These multiple processor shares memory bus, memory and devices.
Two types of multiprocessing OS
Symmetric
Asymmetric
Enhanced performance
Fast processing
More Reliable
Multiprocessing Operating Systems
Real-Time Systems
Used in real-time systems where the time constraints are fixed and followed strictly.
Well-defined fixed-time constraints.
If system does not produce within time constraints it will be failed.
Used in traffic control, ATM, Robots etc.
Two types:
Soft: Less Strict time
Hard: Very strict time constraint
Process States
As a process executes, it changes states
Each process is represented in the operating system by a process control block (PCB)
Also called task control block
When the process is created by the operating system it creates a data structure to store the
information of that process. This is known as Process Control Block (PCB).
A Process Control block (PCB) is a data structure that stores information about each process.
Process Control Block (PCB)…
Process Control Block (PCB)
Process state: The state may be new, ready, running, waiting, halted and so on.
Program counter: The counter indicates the address of the next instruction to be executed for
this process.
CPU registers: The registers vary in number and type, depending on the computer
architecture.
They include accumulators, index registers, stack pointers and general-purpose registers,
plus any condition code information. Along with the program counter, this state
information must be saved when an interrupt occurs, to allow the process to be continued
correctly afterwards.
Process Control Block (PCB) …
CPU Scheduling information: This information includes a process priority, pointers to
scheduling queues, and any other scheduling parameters
Accounting Information: This information includes the amount of CPU and real time used,
time
limits, account numbers, job or process numbers, and so on.
I/O Status Information: The information includes the list of I/O devices allocated to the
process, a list of open files, and so on many pieces of information associated with a specific
process, including
PCB simply serves as the repository for any information that may vary from process to process
Process scheduling
We have already studies that more than one processes can be executed in case of Multi-
programming and Time sharing system
Process scheduler selects an available process (possibly from a set of several available
processes) for program execution on the CPU
A uniprocessor system can have only one running process at a given time. If
more processes exist, the rest must wait until the CPU is free and can be
rescheduled
Context switch
Switching the CPU from one process to another requires saving of the context of the
current process and loading the state of the new process
Context Switching
CPU Scheduling
CPU Scheduling
Basic concept
Objective of multiprogramming is to have some process running at all times, in order to maximize
CPU utilization.
In multiprogramming, a process is executed until it must wait, typically for the completion of some
I/O request.
When one process has to wait, the OS takes the CPU away from that process and gives the CPU to
another process.
Life of a process
Process execution consist cycle of CPU execution and I/O wait.
Processes alternates between these two states.
Process starts from CPU burst, followed by I/O wait and so on.
Process terminates upon the CPU burst.
Life of a Process
CPU Scheduler…
Short-term scheduler selects a process from among the processes in the ready queue
Invokes the dispatcher to have the CPU allocated to the selected process
Ready queue can be implemented as a FIFO queue, a tree, or simply an unordered linked list
and records in ready queue are PCB of processes
Dispatcher gives control of the CPU to the process selected by the short-term scheduler;
this function involves:
Switching context – saving current process context and load the context of another
Dispatch latency – time it takes for the dispatcher to stop one process and start another
running.
Typically, a few microseconds
Scheduling Criteria
CPU utilization
Keep the CPU as busy as possible
Throughput
Number of processes that complete their execution per time unit
Turnaround time
Amount of time to execute a particular process = CPU + I/O + Wait of memory + Waiting
time
Waiting time
Amount of time a process has been waiting in the ready queue
Response time
Amount of time it takes from when a request was submitted until the first response
is produced, not output (for time-sharing environment)
Optimization Criteria
Maximize CPU utilization
Maximize throughput
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
P1 0 8
P2 1 4
P3 2 6
P4 3 2
First Come First Scheduling (FCFS)…
Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
P1 0 8 8 8 0 0
P2 1 4 12 11 7 7
P3 2 6 18 16 10 10
P4 3 2 20 17 15 15
First Come First Scheduling (FCFS)…
Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
P1 0 2
P2 1 2
P3 5 3
P4 6 4
First Come First Scheduling (FCFS)…
Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
P1 0 2 2 2 0 0
P2 1 2 4 3 1 1
P3 5 3 8 3 0 0
P4 6 4 12 6 2 2
Shortest Job First Scheduling (SJF)
Process with the shortest CPU burst is scheduled first.
Preemptive – if a new process arrives with CPU burst length less than remaining time of
current executing process, preempt it—Shortest-Remaining-Time-First (SRTF).
0 12 16
7
Average waiting time = (0+6+3+7)/4 = 4
Non-Preemptive SJF
Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
P1 1 3
P2 2 4
P3 1 2
P4 4 4
Non-Preemptive SJF
Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
P1 1 3 6 5 2 2
P2 2 4 10 8 4 4
P3 1 2 3 2 0 0
P4 4 4 14 10 6 6
Preemptive SJF
Gantt chart
P1 P2 P3 P2 P4 P1
0 2 4 5 11 16
7
Average waiting time = (9 + 1 + 0 +2)/4 = 3
Preemptive SJF
Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
P1 0 5
P2 1 3
P3 2 4
P4 4 1
Preemptive SJF
Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
P1 0 5 9 9 4 0
P2 1 3 4 3 0 0
P3 2 4 13 11 7 7
P4 4 1 5 1 0 0
Priority Scheduling
A priority number (integer) is associated with each process
The CPU is allocated to the process with the highest priority (higher integer highest
priority).
Preemptive
Non-preemptive
SJF is a priority scheduling where priority is the predicted next CPU burst time.
Priority Scheduling
Priority Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
10 P1 0 5
20 P2 1 4
30 P3 2 2
40 P4 4 1
Priority Scheduling
Priority Process Arrival Time Burst Time Completion time Turn around time Waiting time Response time
10 P1 0 5 12 12 7
20 P2 1 4 8 7 3
30 P3 2 2 4 2 0
40 P4 4 1 5 1 0
Any Question?
Thank you