0% found this document useful (0 votes)
9 views

Final Unit 4 Spos 2023

SPOS university examination important topics

Uploaded by

nairabin314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Final Unit 4 Spos 2023

SPOS university examination important topics

Uploaded by

nairabin314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 101

“OPERATING SYSTEM”

Prepared By
Prof. Anand N. Gharu
(Assistant Professor)
PVGCOE Computer Dept.

CLASS : TE COMPUTER 2019


SUBJECT : SPOS (SEM-I) 27 OCT 2023
.UNIT : IV
CONTENTS :-
1. Introduction: Evolution of OS
2. Operating System Services
3. Functions of Operating System.
4. Process Management: Process, Process States: 5 and 7
state model
5. Process control block
6. Threads, Thread lifecycle, Multithreading Model,
Process control system calls.
7. Process Scheduling: Uni-processor Scheduling,
Scheduling: Preemptive, Non-preemptive, Long-term,
Medium-term, Short term scheduling. Scheduling
Algorithms:
Prof. Gharu Anand N.
FCFS, SJF, RR, and Priority. 2
What’s operating system?
• An Operating System (OS) is an interface between a computer user and
computer hardware. An operating system is a software which performs all
the basic tasks like file management, memory management, process
management, handling input and output, and controlling peripheral devices
such as disk drives and printers.

Prof. Gharu Anand N. 3


Evolution of OS
Operating system is divided into four generations, which are explained as follows

1. First Generation (1945-1955) :
It is the beginning of the development of electronic computing systems which are
substitutes for mechanical computing systems. Because of the drawbacks in
mechanical computing systems like, the speed of humans to calculate is limited and
humans can easily make mistakes. In this generation there is no operating system, so
the computer system is given instructions which must be done directly.
Example − Type of operating system and devices used is Plug Boards.

Second Generation (1955-1965)


The Batch processing system was introduced in the second generation, where a job or
a task that can be done in a series, and then executed sequentially. In this generation,
the computer system is not equipped with an operating system, but several operating
system functions exist like FMS and IBSYS.
Prof. Gharu Anand N. 4
Example − Type of operating system and devices used is Batch systems.
SERVICES
OF
OPERATING
SYSTEM
Prof. Gharu Anand N. 5
Services of Operating System
• Program execution

• I/O operations

• File System manipulation

• Communication

• Error Detection

• Resource Allocation

• Protection
Prof. Gharu Anand N. 6
• Program execution
• Operating systems handle many kinds of activities from user programs to
system programs like printer spooler, name servers, file server, etc. Each
of these activities is encapsulated as a process.
• A process includes the complete execution context (code to execute, data
to manipulate, registers, OS resources in use). Following are the major
activities of an operating system with respect to program management −
• Loads a program into memory.
• Executes the program.
• Handles program's execution.
• Provides a mechanism for process synchronization.
• Provides a mechanism for process communication.
• Provides a mechanism for deadlock handling.
Prof. Gharu Anand N. 7
• I/O Operation
• An I/O subsystem comprises of I/O devices and their
corresponding driver software. Drivers hide the peculiarities
of specific hardware devices from the users.
• An Operating System manages the communication between
user and device drivers.
• I/O operation means read or write operation with any file or
any specific I/O device.
• Operating system provides the access to the required I/O
device when required.
Prof. Gharu Anand N. 8
• File system manipulation
• A file represents a collection of related information. Computers can
store files on the disk (secondary storage), for long-term storage
purpose. Examples of storage media include magnetic tape, magnetic
disk and optical disk drives like CD, DVD. Each of these media has its
own properties like speed, capacity, data transfer rate and data access
methods.
• Following are the major activities of an operating system with respect
to file management −
• Program needs to read a file or write a file.
• The operating system gives the permission to the program for
operation on file.
• Permission varies from read-only, read-write, denied and so on.
• Operating System provides an interface to the user to create/delete
files.
• Operating System provides an interface to the user to create/delete
directories.
• Operating
Prof. Gharu Anand N.
System provides an interface to create the backup of file 9
• Communication
• In case of distributed systems which are a collection of processors that
do not share memory, peripheral devices, or a clock, the operating
system manages communications between all the processes. Multiple
processes communicate with one another through communication lines
in the network.

• Some activities are :

• Two processes often require data to be transferred between them

• Both the processes can be on one computer or on different computers,


but are connected through a computer network.

• Communication may be implemented by two methods, either by


Shared
Prof. GharuMemory
Anand N. or by Message Passing. 10
• Error handling
• Errors can occur anytime and anywhere. An error may occur in CPU,
in I/O devices or in the memory hardware. Following are the major
activities of an operating system with respect to error handling −
• The OS constantly checks for possible errors.
• The OS takes an appropriate action to ensure correct and consistent
computing.
• Resource Management

• In case of multi-user or multi-tasking environment, resources such as


main memory, CPU cycles and files storage are to be allocated to each
user or job. Following are the major activities of an operating system
with respect to resource management −

• The OS manages all kinds of resources using schedulers.

• CPU scheduling
Prof. Gharu Anand N. algorithms are used for better utilization of CPU. 11
• Protection
• Considering a computer system having multiple users and concurrent
execution of multiple processes, the various processes must be
protected from each other's activities.

• Protection refers to a mechanism or a way to control the access of


programs, processes, or users to the resources defined by a computer
system.

• The OS ensures that all access to system resources is controlled.

• The OS ensures that external I/O devices are protected from invalid
access attempts.

• The OS provides authentication features for each user by means of


passwords.
Prof. Gharu Anand N. 12
FUNCTION
OF
OPERATING
SYSTEM
Prof. Gharu Anand N. 13
Function of Operating System
• Memory Management
• Processor Management
• Device Management
• File Management
• Security
• Resource sharing & protection
• Job accounting
• Error detection
• Coordination between other software and users
(Accounting)
Prof. Gharu Anand N. 14
Memory management
Memory management refers to management of Primary Memory or Main Memory.
Main memory is a large array of words or bytes where each word or byte has its own
address.

- Main memory provides a fast storage that can be accessed directly by the CPU. For
a program to be executed, it must in the main memory. An Operating System does
the following activities for memory management −

- Keeps tracks of primary memory, i.e., what part of it are in use by whom, what part
are not in use.

- In multiprogramming, the OS decides which process will get memory when and
how much.

- Allocates the memory when a process requests it to do so.

Prof. Gharu Anand


- De-allocates N.
the memory 15
when a process no longer needs it or has been terminated.
Process management
In multiprogramming environment, the OS decides which process
gets the processor when and for how much time. This function is
called process scheduling.

An Operating System does the following activities for


processor management −

- Keeps tracks of processor and status of process. The program


responsible for this task is known as traffic controller.

- Allocates the processor (CPU) to a process.

- De-allocates processor
Prof. Gharu Anand N.
when a process is no longer required. 16
Device management
An Operating System manages device communication via their
respective drivers.

It does the following activities for device management −

- Keeps tracks of all devices. Program responsible for this task is


known as the I/O controller.

- Decides which process gets the device when and for how much
time.

- Allocates the device in the efficient way.

- De-allocates
Prof. Gharu Anand devices.
N. 17
File management
A file system is normally organized into directories for easy
navigation and usage. These directories may contain files and other
directions.

An Operating System does the following activities for file


management −
- Keeps track of information, location, uses, status etc. The
collective facilities are often known as file system.
- Decides who gets the resources.
- Allocates the resources.
- De-allocates the resources.
Prof. Gharu Anand N. 18
Other activities are :
Security − By means of password and similar other techniques, it
prevents unauthorized access to programs and data.
Control over system performance − Recording delays between
request for a service and response from the system.
Job accounting − Keeping track of time and resources used by
various jobs and users.
Error detecting aids − Production of dumps, traces, error
messages, and other debugging and error detecting aids.
Coordination between other softwares and users − Coordination
Prof. Gharu Anand N. 19
and assignment of compilers, interpreters, assemblers and other
TYPES
OF
OPERATING
SYSTEM
Prof. Gharu Anand N. 20
Types of Operating System
1. Batch Operating System

2. Time-Sharing Operating System

3. Embedded Operating System

4. Multiprogramming Operating System

5. Network Operating System

6. Distributed Operating System

7. Multiprocessing Operating System


Prof. Gharu Anand N. 21
8. Real-Time Operating System
Batch Operating System

Prof. Gharu Anand N. 22


Batch Operating System
The users of a batch operating system do not interact with the
computer directly. Each user prepares his job on an off-line device
like punch cards and submits it to the computer operator. To speed
up processing, jobs with similar needs are batched together and run
as a group. The programmers leave their programs with the
operator and the operator then sorts the programs with similar
requirements into batches.
The problems with Batch Systems are as follows −
Lack of interaction between the user and the job.

CPU is often idle, because the speed of the mechanical I/O devices
is slower than the CPU.

Difficult toAnand
Prof. Gharu provide
N. the desired priority. 23
Multitasking

Prof. Gharu Anand N. 24


Multitasking
Multitasking is when multiple jobs are executed by the CPU
simultaneously by switching between them. Switches occur so frequently
that the users may interact with each program while it is running. An OS
does the following activities related to multitasking −
The user gives instructions to the operating system or to a program
directly, and receives an immediate response.
The OS handles multitasking in the way that it can handle multiple
operations/executes multiple programs at a time.
Multitasking Operating Systems are also known as Time-sharing systems.
These Operating Systems were developed to provide interactive use of a
computer system at a reasonable cost.
A time-shared operating system uses the concept of CPU scheduling and
multiprogramming to provide each user with a small portion of a time-
shared CPU.
Prof. Gharu Anand N. 25
Each user has at least one separate program in memory.
Multiprogramming

Prof. Gharu Anand N. 26


Multiprogramming
When two or more programs reside in memory at the same time, is referred
as multiprogramming. Multiprogramming assumes a single shared
processor. Multiprogramming increases CPU utilization by organizing jobs
so that the CPU always has one to execute.

An OS does the following activities related to multiprogramming.

The operating system keeps several jobs in memory at a time.

This set of jobs is a subset of the jobs kept in the job pool.

The operating system picks and begins to execute one of the jobs in the
memory.

Multiprogramming operating systems monitor the state of all active


programs and system resources using memory management programs to
Prof. Gharu Anand N. 27
ensures that the CPU is never idle, unless there are no jobs to process.
Spooling

Prof. Gharu Anand N. 28


Spooling
Spooling is an acronym for simultaneous peripheral operations on line.
Spooling refers to putting data of various I/O jobs in a buffer. This buffer is
a special area in memory or hard disk which is accessible to I/O devices.

An operating system does the following activities related to distributed


environment −

Handles I/O device data spooling as devices have different data access rates.

Maintains the spooling buffer which provides a waiting station where data
can rest while the slower device catches up.

Maintains parallel computation because of spooling process as a computer


can perform I/O in parallel fashion. It becomes possible to have the
Prof. Gharu Anand N. 29
computer read data from a tape, write data to disk and to write out to a tape
Time sharing Operating System
Time-sharing is a technique which enables many people, located at
various terminals, to use a particular computer system at the same
time. Time-sharing or multitasking is a logical extension of
multiprogramming. Processor's time which is shared among
multiple users simultaneously is termed as time-sharing.
Advantages of Timesharing operating systems are as follows −
Provides the advantage of quick response.
Avoids duplication of software.
Reduces CPU idle time.
Disadvantages of Time-sharing operating systems are as follows −
Problem of reliability.
Question of security and integrity of user programs and data.
Problem of data
Prof. Gharu Anand communication.
N. 30
Distributed Operating System
Distributed systems use multiple central processors to serve multiple real-
time applications and multiple users. Data processing jobs are distributed
among the processors accordingly.
The processors communicate with one another through various
communication lines (such as high-speed buses or telephone lines). These
are referred as loosely coupled systems or distributed systems. Processors
in a distributed system may vary in size and function. These processors are
referred as sites, nodes, computers, and so on.
The advantages of distributed systems are as follows −
- Speedup the exchange of data with one another via electronic mail.
- If one site fails in a distributed system, the remaining sites can potentially
continue operating.
- Better service to the customers.
- Reduction of the load on the host computer.
- Reduction of delays in data processing.
Prof. Gharu Anand N. 31
Network Operating System
A Network Operating System runs on a server and provides the
server the capability to manage data, users, groups, security,
applications, and other networking functions. The primary purpose
of the network operating system is to allow shared file and printer
access among multiple computers in a network, typically a local
area network (LAN), a private network or to other networks.

Examples of network operating systems include Microsoft


Windows Server 2003, Microsoft Windows Server 2008, UNIX,
Linux, Mac OS X, Novell NetWare, and BSD.
Prof. Gharu Anand N. 32
Real time Operating System
A real-time system is defined as a data processing system in which
the time interval required to process and respond to inputs is so
small that it controls the environment. The time taken by the
system to respond to an input and display of required updated
information is termed as the response time. So in this method, the
response time is very less as compared to online processing.

Example, Scientific experiments, medical imaging systems,


industrial control systems, weapon systems, robots, air traffic
control systems, etc.
Prof. Gharu Anand N. 33
PROCESS .

MANAGEMENT
CONCEPTS
Prof. Gharu Anand N. 34
Process

Prof. Gharu Anand N. 35


Process
• A process is a program in execution. Process is not as same as
program code but a lot more than it. A process is an 'active' entity as
opposed to program which is considered to be a 'passive' entity.
Attributes held by process include hardware state, memory, CPU etc.

• Process memory is divided into four sections for efficient working :


• The text section is made up of the compiled program code, read in
from non-volatile storage when the program is launched.
• The data section is made up the global and static variables, allocated
and initialized prior to executing the main.
• The heap is used for the dynamic memory allocation, and is
managed via calls to new, delete, malloc, free, etc.
• The stack is used for local variables. Space on the stack is reserved
for local variables when they are declared.
Prof. Gharu Anand N. 36
Five State Process

Prof. Gharu Anand N. 37


Five State Process
1. New − When a new process is created, It enter into the new state. Then it tries to
load into RAM.

2. Ready − The processes that are loaded on RAM and waiting for CPU are in ready
state.

3. Running − The processes that are running on the CPU are in running state.

If the process is running in its critical section, then other processes need to wait in the
ready state.

4. Blocked − All processes that are leaving the CPU and moving to the waiting state
are in the blocked state. When the CPU becomes free, processes from the blocked state
again move to the ready state, and from ready to Running state.

5. Exit / Terminated − A process that is terminated from CPU and RAM is in the
terminate state.. 38
Seven State Process

Prof. Gharu Anand N. 39


Seven State Process
1. New − Contains the processes that are newly coming for execution.

2. Ready − Contains the processes that are present in main memory and available for
execution.

3. Running − Contains the process that is running or executing.

4. Exit − Contains the processes that complete its execution.

5. Blocked − Contains the processes that are present in main memory and awaiting an
event to occur.

6. Blocked Suspend − It contains the process present in secondary memory and


awaits an event to occur.

7. Ready Suspend − Contains the processes that are present in secondary memory but
is available for execution as soon as it is loaded into main memory.
40
Process Control Block

Prof. Gharu Anand N. 41


Process Control Block
Process State - This specifies the process state i.e. new, ready, running,
waiting or terminated..

Process ID, and parent process ID.: This shows the number of the
particular process

Program Counter - This contains the address of the next instruction


that needs to be executed in the process.

Registers -

This specifies the registers that are used by the process. They may
include accumulators, index registers, stack pointers, general purpose
registers etc.
Prof. Gharu Anand N. 42
Process Control Block
List of Open Files :

These are the different files that are associated with the process

CPU Scheduling Information :

The process priority, pointers to scheduling queues etc. is the CPU


scheduling information that is contained in the PCB. This may also
include any other scheduling parameters.

Memory Management Information :

The memory management information includes the page tables or the


segment tables depending on the memory system used. It also contains
the value of the base registers, limit registers etc..
Prof. Gharu Anand N. 43
Process Control Block
I/O Status Information :

This information includes the list of I/O devices used by the process,
the list of files etc

Accounting information :

The time limits, account numbers, amount of CPU used, process


numbers etc. are all a part of the PCB accounting information

Prof. Gharu Anand N. 44


Process Control Block

Prof. Gharu Anand N. 45


CPU switch from process to process using PCB
THREAD IN
OS
Prof. Gharu Anand N. 46
Thread concepts
Thread is an execution unit which consists of its own program counter, a stack,
and a set of registers. Threads are also known as Lightweight processes. Threads
are popular way to improve application through parallelism. The CPU switches rapidly
back and forth among the threads giving illusion that the threads are running in parallel.
As each thread has its own independent resource for process execution, multpile
processes can be executed parallely by increasing number of threads.

Prof. Gharu Anand N. 47


Types of Thread
There are two types of threads :

1. User Threads

2. Kernel Threads

User threads, are above the kernel and without kernel support. These are
the threads that application programmers use in their programs.

Kernel threads are supported within the kernel of the OS itself. All modern
OSs support kernel level threads, allowing the kernel to perform multiple
simultaneous tasks and/or to service multiple kernel system calls
simultaneously.

Prof. Gharu Anand N. 48


Advantages of Thread
Responsiveness

Resource sharing, hence allowing better utilization of resources.

Economy. Creating and managing threads becomes easier.

Scalability. One thread runs on one CPU. In Multithreaded


processes, threads can be distributed over a series of processors to
scale.

Context Switching is smooth. Context switching refers to the


procedure followed by CPU to change from one task to another.

.
Prof. Gharu Anand N. 49
Lifecycle of Thread
The life cycle of a thread in an operating system involves the
creation, scheduling, execution, blocking, and termination. The
operating system plays a critical role in managing the life cycle of
threads, ensuring that they run efficiently and effectively.

Prof. Gharu Anand N. 50


Process Vs Thread
Parameter Process Thread
Process means a program is in Thread means a segment of a
Definition
execution. process.
Lightweight The process is not Lightweight. Threads are Lightweight.
Termination The process takes more time to The thread takes less time to
time terminate. terminate.
Creation time It takes more time for creation. It takes less time for creation.

Communication between threads


Communication between processes
Communication requires less time compared to
needs more time compared to thread.
processes.

Context It takes more time for context It takes less time for context
switching time switching. switching.
Resource Process consume more resources. Thread consume fewer resources.

Treatment by Different process are tread separately All the level peer threads are
OS by OS. treated as a single task by OS.

Memory The process is mostly isolated. Threads share memory.


Prof. Gharu Anand N. 51
Sharing It does not share data Threads share data with each other.
Process Vs Thread
Sr.
Process Thread
No.
Process means any program is in
1. Thread means segment of a process.
execution.
Process takes more time to
2. Thread takes less time to terminate.
terminate.
3. It takes more time for creation. It takes less time for creation.
It also takes more time for context It takes less time for context
4.
switching. switching.
Process is less efficient in term of Thread is more efficient in term of
5.
communication. communication.
6. Process consume more resources. Thread consume less resources.
7. Process is isolated. Threads share memory.
Process is called heavy weight
8. Thread is called light weight process.
process.
Thread switching does not require to
Process switching uses interface in
9. call a operating system and cause an
operating system.
interrupt to the kernel.
If one process is blocked then it will Second thread in the same task could
Prof. Gharu Anand N. 52
10. not effect the execution of other not run, while one server thread is
Component of OS
• System call :
In computing, a system call is the programmatic way in which a computer
program requests a service from the kernel of the operating system it is
executed on. A system call is a way for programs to interact with the
operating system. A computer program makes a system call when it makes a
request to the operating system’s kernel. System call provides the services of
the operating system to the user programs via Application Program
Interface(API). It provides an interface between a process and operating
system to allow user-level processes to request services of the operating
system. System calls are the only entry points into the kernel system. All
Prof. Gharu
programs Anand N.
needing resources must use system calls 53
System call
Services Provided by System Calls :
• Process creation and management
• Main memory management
• File Access, Directory and File system management
• Device handling(I/O)
• Protection
• Networking, etc.
Types of System Calls : There are 5 different categories of system calls –
Process control: end, abort, create, terminate, allocate and free memory.
File management: create, open, close, delete, read file etc.
Device management
Information maintenance
Prof. Gharu Anand N. 54
System call

Prof. Gharu Anand N. 55


System call
UNIX
WINDOWS

CreateProcess() ExitProcess()
Process Control fork() exit() wait()
WaitForSingleObject()

CreateFile() ReadFile()
File Manipulation open() read() write() close()
WriteFile() CloseHandle()

SetConsoleMode() ReadConsole()
Device Manipulation ioctl() read() write()
WriteConsole()

GetCurrentProcessID()
Information Maintenance getpid() alarm() sleep()
SetTimer() Sleeo()

CreatePipe() CreateFileMapping()
Communication pipe() shmget() mmap()
MapViewOfFile()

SetFileSecurity()
Protection InitlializeSecurityDescriptor() chmod() umask() chown()
Prof. Gharu Anand N. SetSecurityDescriptorGroup() 56
PROCESS
SCHEDULLING

Prof. Gharu Anand N. 57


Process Schedulling
The process scheduling is the activity of the process manager that
handles the removal of the running process from the CPU and the
selection of another process on the basis of a particular strategies. Process
scheduling is an essential part of a Multiprogramming operating systems.

Prof. Gharu Anand N. 58


Process Schedulling

Prof. Gharu Anand N. 59


Process Schedulling
An operating system uses two types of scheduling processes
execution, preemptive and non - preemptive.

1. Preemptive process:
In preemptive scheduling policy, a low priority process has to be suspend
its execution if high priority process is waiting in the same queue for its
execution.

2. Non - Preemptive process:


In non - preemptive scheduling policy, processes are executed in first
come first serve basis, which means the next process is executed only
when currently running process finishes its execution.
Prof. Gharu Anand N. 60
.
Types of scheduler
1) Long Term Scheduler

It selects the process that are to be placed in ready queue. The


long term scheduler basically decides the priority in which
processes must be placed in main memory. Processes of long term
scheduler are placed in the ready state because in this state the
process is ready to execute waiting for calls of execution from
CPU which takes time that’s why this is known as long term
scheduler.

Prof. Gharu Anand N. 61


Types of scheduler
2) Mid – Term Scheduler
It places the blocked and suspended processes in the secondary memory of
a computer system. The task of moving from main memory to secondary
memory is called swapping out.The task of moving back a swapped out
process from secondary memory to main memory is known as swapping
in. The swapping of processes is performed to ensure the best utilization
of main memory.

3) Short Term Scheduler

It decides the priority in which processes is in the ready queue are


allocated the central processing unit (CPU) time for their execution. The
short term scheduler is also referred as central processing unit (CPU)
scheduler.
Prof. Gharu Anand N. 62
Compare types of scheduler
S.N. Long-Term Short-Term Medium-Term
Scheduler Scheduler Scheduler
1 It is a job scheduler It is a CPU scheduler
It is a process
swapping scheduler.
2 Speed is lesser than Speed is fastest among Speed is in between
short term scheduler other two both short and long
term scheduler.
3 It controls the degree It provides lesser It reduces the degree of
of multiprogramming control over degree of multiprogramming.
multiprogramming

4 It is almost absent or It is also minimal in It is a part of Time


minimal in time time sharing system sharing systems.
sharing system
5 It selects processes It selects those It can re-introduce the
from pool and loads processes which are process into memory
them into memory for ready to execute and execution can be
Prof.execution
Gharu Anand N. continued. 63
Schedulling criteria
CPU utilization : To make out the best use of CPU and not to waste any
CPU cycle, 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 90% (heavily loaded.)

Throughput : It is the total number of processes completed per unit time


or rather say total amount of work done in a unit of time. This may range
from 10/second to 1/hour depending on the specific processes.

Turnaround time : It is the amount of time taken to execute a particular


process, i.e. The interval from time of submission of the process to the
time of completion of the process(Wall clock time).
Prof. Gharu Anand N. 64
Schedulling criteria
Waiting time : The sum of the periods spent waiting in the ready queue
amount of time a process has been waiting in the ready queue to acquire
get control on the CPU.

Load average : It is 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).

Prof. Gharu Anand N. 65


SCHEDULLING
ALGORITHMS
Prof. Gharu Anand N. 66
Schedulling Algorithms
1. First-Come, First-Served (FCFS) Scheduling

2. Shortest-Job-First (SJF) Scheduling

3. Priority Scheduling

4. Round Robin(RR) Scheduling

5. SJF Preemptive Scheduling

Prof. Gharu Anand N. 67


FCFS Algorithms
 Jobs are executed on first come, first serve basis.

 It is a non-preemptive, pre-emptive scheduling


algorithm.

 Easy to understand and implement.

 Its implementation is based on FIFO queue.

 Poor in performance as average wait time is high

Prof. Gharu Anand N. 68


FCFS Algorithms

Prof. Gharu Anand N. 69


FCFS Algorithms

Prof. Gharu Anand N. 70


FCFS Algorithms

Prof. Gharu Anand N. 71


FCFS Algorithms

Prof. Gharu Anand N. 72


FCFS Algorithms

TAT=FT-AT WT=TAT-BT

Prof. Gharu Anand N. 73


FCFS Algorithms

Prof. Gharu Anand N. 74


FCFS Algorithms

Prof. Gharu Anand N. 75


FCFS Algorithms

Prof. Gharu Anand N. 76


FCFS Algorithms

Prof. Gharu Anand N. 77


SJF(SJN) Algorithms
 This is also known as shortest job first, or SJF

 This is a non-preemptive, pre-emptive scheduling algorithm.

 Best approach to minimize waiting time.

 Easy to implement in Batch systems where required CPU time


is known in advance.

 Impossible to implement in interactive systems where required


CPU time is not known.

 The processor should know in advance how much time process


will take.
Prof. Gharu A.nand N. 78
SJF(SJN) Algorithms

Prof. Gharu Anand N. 79


SJF(SJN) Algorithms

Prof. Gharu Anand N. 80


SJF(SJN) Algorithms

Prof. Gharu Anand N. 81


SJF(SJN) Algorithms
TAT=FT-AT WT=TAT-CT

Prof. Gharu Anand N. 82


SJF(SJN) Algorithms

Prof. Gharu Anand N. 83


SJF(SJN) Algorithms

Prof. Gharu Anand N. 84


RR Algorithms
 Round Robin is the preemptive process scheduling algorithm.

 Each process is provided a fix time to execute, it is called


a quantum.

 Once a process is executed for a given time period, it is preempted


and other process executes for a given time period.

 Context switching is used to save states of preempted processes.

Prof. Gharu Anand N. 85


RR Algorithms
How to compute below times in Round Robin using a program?

• Completion Time: Time at which process completes its


execution.

• Turn Around Time: Time Difference between completion time


and arrival time.

Turn Around Time = Completion Time – Arrival Time

• Waiting Time(W.T): Time Difference between turn around time


and burst time.

Waiting Time = Turn Around Time – Burst Time


Prof. Gharu Anand N. 86
RR Algorithms

Time Quantum is 5

Prof. Gharu Anand N. 87


RR Algorithms

Prof. Gharu Anand N. 88


RR Algorithms

Prof. Gharu Anand N. 89


RR Algorithms

Prof. Gharu Anand N. 90


RR Algorithms

Prof. Gharu Anand N. 91


RR Algorithms

Prof. Gharu Anand N. 92


RR Algorithms

Prof. Gharu Anand N. 93


RR Algorithms

Prof. Gharu Anand N. 94


SJF Preemption Algorithms

Prof. Gharu Anand N. 95


SJF Preemption Algorithms

Prof. Gharu Anand N. 96


SJF Preemption Algorithms

Prof. Gharu Anand N. 97


SJF Preemption Algorithms

Prof. Gharu Anand N. 98


SJF Preemption Algorithms

Prof. Gharu Anand N. 99


Priority Algorithms
 Priority scheduling is a non-preemptive algorithm and one of the most
common scheduling algorithms in batch systems.

 Each process is assigned a priority. Process with highest priority is to


be executed first and so on.

 Processes with same priority are executed on first come first served
basis.

 Priority can be decided based on memory requirements, time


requirements or any other resource requirement.

Prof. Gharu Anand N. 100


THANK YOU!!!
My Blog : https://anandgharu.wordpress.com/

Email : [email protected]

You might also like