Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views31 pages

OS (Unit 1)

Uploaded by

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

OS (Unit 1)

Uploaded by

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

SJR College Department Of Computer Science

Unit-1 Syllabus

Introduction: Computer System Organization, Architecture, Structure, Operations,

Process Management, Memory Management, Storage Management, Kernel Data

Structures, Computing Environments. Operating System Structures: Services, System

Calls, Types, Operating System Structure, System Boot Processes: Process Concept,

Scheduling, Operations, Inter process Communication. Multithreaded Programming:

Multicore Programming, Multithreading Models.

III Sem BCA Operating System Unit I- 1


SJR College Department Of Computer Science

Computer system organization

The basic organization of a computer system is the processing unit, memory unit,
and input-output devices. The processing unit controls all the functions of the
computer system. It is the brain of the computer e.g. CPU. The memory unit
consists of two units.

1. CPU – central processing unit


2. Memory
3. Input devices
4. Output devices

CPU – central processing unit Introduction


It is alternatively referred to as the brain of the computer, processor, central processor,
or microprocessor, the CPU (pronounced as C-P-U) was first developed at Intel with
the help of Ted Hoff in the early 1970’s and is short for Central Processing Unit. The
computer CPU is responsible for handling all instructions it receives from hardware and
software running on the computer.
CPU is considered as the brain of the computer. CPU performs all types of data
processing operations. It stores data, intermediate results and instructions (program).It
controls the operation of all parts of computer.

III Sem BCA Operating System Unit I- 2


SJR College Department Of Computer Science

CPU itself has following three components

1. ALU (Arithmetic Logic Unit)


All arithmetic calculations and logical operation are performed using the
Arithmetic/Logical Unit or ALU

2. Memory Unit
A memory is just like a human brain. It is used to store data and instruction. Computer
memory is use to Stores information being processed by the CPU

3. Control Unit
Control unit help to perform operations of input unit, output unit, Memory unit and ALU
in a sequence.

Memory
Computer memory is any physical device capable of storing information temporarily or
permanently. For example, Random Access Memory RAM is a type of volatile memory
that is stores information on an integrated circuit, and that is used by the operating system,
software, hardware, or the user.

Computer memory divide into two parts

1. Volatile memory
Volatile memory is a temporary memory that loses its contents when the computer
or hardware device loses power.eg. RAM

2. Non-volatile memory
Non-volatile memory keeps its contents even if the power is lost. Example: ROM or
EPROM is a good example of a non-volatile memory

Input Devices

A device that can be used to insert data into a computer system is called as input device.
It allows people to supply information to computers. An input device is any hardware
device that sends data to the computer, without any input devices, a computer would
only be a display device and not allow users to interact with it, much like a TV.The
most fundamental pieces of information are keystrokes on a keyboard and clicks with a
mouse. These two input devices are essential for you to interact with your computer.
Input devices represent one type of computer peripheral.
Examples of input devices include keyboards, mouse, scanners, digital cameras and
joysticks.

Output Devices

III Sem BCA Operating System Unit I- 3


SJR College Department Of Computer Science

A device which is used to display result from a computer is called as output device.
It Allows people to receive information from computers. An output device is any
peripheral that receives or displays output from a computer. The picture shows an inkjet
printer, an output device that can make a hard copy of anything being displayed on a
monitor. Output device is electronic equipment connected to a computer and used to
transfer data out of the computer in the form of text, images, sounds or print.
Examples of output devices include Printer, Scanner, Monitor, etc.

An Operating System (OS) is a software that acts as an interface between


computer hardware components and the user. Every computer system must
have at least one operating system to run other programs. Applications like
Browsers, MS Office, Notepad Games, etc., need some environment to run
and perform its tasks.

The OS helps you to communicate with the computer without knowing how to
speak the computer's language. It is not possible for the user to use any
computer or mobile device without having an operating system.

Objectives of Operating System (OS)


1. To control and coordinate the use of system resources
2. To provide convenient use environment for a user to access the resources
3. To increase the productivity of resources

Types of Operating System (OS)

Following are the popular types of Operating System:

 Batch Operating System


 Multitasking/Time Sharing OS
 Multiprocessing OS
 Real Time OS
 Distributed Operating System

Batch Operating System

Some computer processes are very lengthy and time-consuming. To speed


the same process, a job with a similar type of needs are batched together
and run as a group.

The user of a batch operating system never directly interacts with the
computer. In this type of OS, every user prepares his or her job on an offline
device like a punch card and submit it to the computer operator.

III Sem BCA Operating System Unit I- 4


SJR College Department Of Computer Science

The batch operating system grouped jobs that perform similar functions. These job
groups are treated as a batch and executed simultaneously. A computer system with this
operating system performs the following batch processing activities:

Advantages

 Batch processing takes much of the work of the operator to the


computer.
 Increased performance as a new job get started as soon as
the previous job is finished, without any manual
intervention.
Disadvantages
 Difficult to debug program.
 A job could enter an infinite loop.
 Due to lack of protection scheme, one batch job can affect pending
jobs.

Multiprogramming

Sharing the processor, 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.
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

III Sem BCA Operating System Unit I- 5


SJR College Department Of Computer Science

The following figure shows the memory layout for a multiprogramming system.

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.
programs and system resources using memory management programs
to ensures that the CPU is never idle, unless there are no jobs to
process.

Advantages
 High and efficient CPU utilization.
 User feels that many programs are allotted CPU almost
simultaneously.
 Increases resource utilisation

Disadvantages

 CPU scheduling is required.


 To accommodate many jobs in memory, memory management is
required.
 Shorter jobs have to wait for longer duration of time.

III Sem BCA Operating System Unit I- 6


SJR College Department Of Computer Science

Multi-user/Time Sharing operating System

A multi-user operating system is an operating system that permits several users to access
a single system running to a single operating system. It is a logical extension of Multi
programming. The system switches rapidly form one user to the next. The user is given
an impression that entire system is dedicated to one user. Users will usually sit at
terminals or computers connected to the system via a network and other system machines
like printers.

Real Time System


A real time operating system time interval to process and respond to inputs is very
small. Examples: Military Software Systems, Space Software Systems are the Real
time OS
Real-time systems are usually dedicated, embedded systems. An operating system
does the following activities related to real-time system activity.
In such systems, Operating Systems typically read from and react to sensor
data.
The Operating system must guarantee response to events within fixed periods of
time to ensure correct performance.

Distributed System
Distributed systems use many processors located in different machines to
provide very fast computation to its users.
A distributed System refers to multiple independent CPUs or processors in a
computer system. An operating system does the following activities related to
distributed environment −
 The OS distributes work(Computation) among several physical
processors.
 The processors do not share memory or a clock. Instead, each
processor has its own local memory.

III Sem BCA Operating System Unit I- 7


SJR College Department Of Computer Science

 The OS manages the communications between the


processors. They communicate with each other through
various communication lines.
Advantages
 All computers work independently
 Resources are shared
 More reliable as a failure of one system will not impact the
other

Disadvantages
 Costly setup
 If server is failed ,then the whole system will fail.

The kernel data structures


The kernel data structures are very important as they store data about the current state
of the system. For example, if a new process is created in the system, a kernel data
structure is created that contains the details about the process.
Most of the kernel data structures are only accessible by the kernel and its subsystems.
They may contain data as well as pointers to other data structures.
Kernel Components
The kernel stores and organizes a lot of information. So it has data about which
processes are running in the system, their memory requirements, files in use etc. To
handle all this, three important structures are used. These are process table, file table
and v node/ i node information.

Details about these are as follows:


Process Table
The process table stores information about all the processes running in the system. These
include the storage information, execution status, file information etc.
When a process forks a child, its entry in the process table is duplicated including the
file information and file pointers. So the parent and the child process share a file.

III Sem BCA Operating System Unit I- 8


SJR College Department Of Computer Science

File Table
The file table contains entries about all the files in the system. If two or more processes
use the same file, then they contain the same file information and the file descriptor
number.
Each file table entry contains information about the file such as file status (file read or
file write), file offset etc. The file offset specifies the position for next read or write
into the file.
The file table also contains v-node and i-node pointers which point to the virtual node
and index node respectively. These nodes contain information on how to read a file.
V- Node and I-Node Tables
Both the v-node and i-node are references to the storage system of the file and the
storage mechanisms. They connect the hardware to the software.
The v-node is an abstract concept that defines the method to access file data without
worrying about the actual structure of the system. The i-node specifies file access
information like file storage device, read/write procedures etc.

Computing Environments
Computing environment is a collection of computers/machines arranged in different ways to
solve many problems. This constitutes a computing environment where many computers are
used to process and exchange information to handle multiple issues.
Types of computing environments
There are four types of computing environments. They are:

1. Personal computing environment


2. Time-Sharing environment
3. Client -Server environment
4. Distributed environment

Personal Computing Environment:

 A personal computer(PC) is a general purpose computer. The size and capabilities of a


personal computer makes it useful for end-users.
 In a personal computer, all the hardware components are tied together, so that it
can be used as per our need.

III Sem BCA Operating System Unit I- 9


SJR College Department Of Computer Science

Time Sharing Environment

 Employees in large companies often work in a time sharing environment. In this


environment, many users are connected to one or more computers.
 These are minicomputers or central mainframes.
 The terminals used are not programmable, but now we see more microcomputers that
are used to simulate the environments terminals.
 In the time sharing environment, the output devices and auxiliary storage are shared by
all the users.
 In this type of environment, computing is operated by central computer. This central
computer has many duties which keeps the computer busy.
Client Server Environment

 Client/Server is a distribute computing model, in which the client requests services from
the server.
 Client/Server usually run on separate computers connected by a network.
 A client is a process or an application that sends messages to a server through the
network.
 These messages ask the server to perform a specific task, like finding a customer record
in a database.
 Severs usually run on powerful computers, workstations or mainframes
 The administration of the installed equipment is more expensive than maintaining a
 centralized system

Distributed Computing Environment

 A distributed computing environment allows smooth integration of computing


functions between different internet server's clients and provides the connection to
different servers around the world.
 Distributed Computing is used by distributed systems to solve computational problems
 In Distributed Computing, each problem is divided into several tasks, which are
solved by one or more computers.

III Sem BCA Operating System Unit I- 10


SJR College Department Of Computer Science

Operating System services


An Operating System provides services to both the users and to the programs.

 It provides programs an environment to execute.


 It provides users the services to execute the programs in a convenient
manner.
Following are a few common services provided by an operating system

 Program execution
 I/O operations
 File System manipulation Communication
 Error Detection
 Resource Allocation
 Protection

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.

III Sem BCA Operating System Unit I- 11


SJR College Department Of Computer Science

Handles program's execution.


Provides a mechanism for process synchronization.
Provides a mechanism for process communication.
Provides a mechanism for deadlock handling.

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.

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.
A file system is normally organized into directories for easy navigation and
usage. These directories may contain files and other directions. 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 System
provides an interface to create the backup of file system.

Communication

III Sem BCA Operating System Unit I- 12


SJR College Department Of Computer Science

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.
The OS handles routing and connection strategies, and the problems of
contention and security. Following are the major activities of an operating
system with respect to communication −

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
Memory or by Message Passing.

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


algorithms are used for better utilization of CPU.
Protection and Security
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. Following
are the major activities of an operating system with respect to protection −

III Sem BCA Operating System Unit I- 13


SJR College Department Of Computer Science

 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.

System call
A system call is a mechanism that provides the interface between a process
and the operating system. It is a programmatic method in which a computer
program requests a service from the kernel of the OS.
Types of System calls
Here are the five types of system calls used in OS:

 Process Control
 File Management
 Device Management
 Information Maintenance
 Communications
Process Control
This system calls perform the task of process creation, process
termination, etc.
Functions:
 End and Abort Load and Execute
 Create Process and Terminate Process
 Wait and Signal Event
 Allocate and free memory

File Management
File management system calls handle file manipulation jobs like creating a file,
reading, and writing, etc.
Functions:
 Create a file
 Delete file
 Open and close file
 Read, write, replace
 Get and set file attributes
Device Management
Device management does the job of device manipulation like reading from device
buffers, writing into device buffers, etc.
Functions
 Request and release device
 Logically attach devices
 Logically detach devices
 Get and Set device attributes

III Sem BCA Operating System Unit I- 14


SJR College Department Of Computer Science

Information Maintenance
It handles information and its transfer between the OS and the user program.
Functions:
 Get or set time and date
 Get process and device attributes

Communication:
These types of system calls are specially used for inter process
communications.

Functions:
 Create, delete communications connections
 Send, receive message
 Help OS to transfer status information
 Attach or detach remote devices

Process management

Process
Process can be defined as program under execution. Program becomes a
process when it’s executable file is loaded into the memory. A process is an
instance of program execution.

States of Process:

The life-cycle of a process can be described by a state diagram which has


states representing the execution status of the process at various times and
transitions that represent changes in execution status.

As process executes it changes the states. The state of a process is defined by


the current activity of that process.

The process has following states.

New : A process is said to be in new state when a program present in the


secondary memory is initiated for execution.
Ready : When process is in main memory and ready for execution

Running : When process starts execution

Waiting : When process waits for a resource input file or output file

Terminated : A process moves from run state to terminate state


after its execution is completed.

III Sem BCA Operating System Unit I- 15


SJR College Department Of Computer Science

Process State diagram

Process Control Block

For each process there is a Process Control Block, PCB, which stores the following (
types of )
process-specific information, Process State - Running, waiting, etc., as discussed
above.
 Process ID, and parent process ID - It will uniquely identify the process.
 CPU registers and Program Counter - These need to
be saved and restored when swapping processes in and
out of the CPU.
 CPU-Scheduling information - Such as priority
information and pointers to scheduling queues.
 Memory-Management information - E.g. page tables or segment tables.
 Accounting information - user and kernel CPU time
consumed, account numbers, limits,etc.
 I/O Status information - Devices allocated, open file tables, etc.

III Sem BCA Operating System Unit I- 16


SJR College Department Of Computer Science

The operating system maintains management information about a process in a


process control block (PCB). Modern operating systems allow a process to be
divided into multiple threads of execution, which share all process
management information except for information directly related to execution.
This information is held in a thread control block (TCB).

Process Scheduling
The two main objectives of the process scheduling system are to keep the CPU
busy always Scheduling Queues
 All processes are stored in the job queue.
 Processes in the Ready state are placed in the ready queue.
 Processes waiting for a device to become available or to
deliver data are placed in device queues. There is generally
a separate device queue for each device.
 Other queues may also be created and used as needed.

Schedulers

The process migrates among various queues in their life time. The OS has
to select the process for scheduling purpose. The selection is done by
module called scheduler.There are 3 types of scheduler.

III Sem BCA Operating System Unit I- 17


SJR College Department Of Computer Science

1. long-term scheduler is typical of a batch system or a very heavily loaded


system.
 It runs infrequently, ( such as when one process ends selecting one
more to be loadedin from disk in its place ),
 The frequency of invocation is less
 Invoked after a long duration of time
 It is in charge of create to ready transition.

2. short-term scheduler, or CPU Scheduler,


 runs very frequently, on the order of 100 milliseconds, and must
very quickly swap one process out of the CPU and swap in another
one.
 The frequency of invocation is more.
 Invoked after a short duration of time
 It is in charge of ready to run transition.

3. medium-term scheduler.
 When system loads get high, this scheduler will swap one or more
processes out of the ready queue system for a few seconds, in order
to allow smaller faster jobs to finish up quickly and clear the system.
See the differences in Figures 3.7 and 3.8 below.
 It is in charge of suspended to ready transition.
 The frequency of invocation is in between the remaining two types.

Types of Scheduling

1) Non pre-emptive Scheduling: Once the CPU is given to a


process it can not be taken away from that process.

III Sem BCA Operating System Unit I- 18


SJR College Department Of Computer Science

2) pre-emptive Scheduling: Once the CPU is given to a process it can not be taken
away
from that process.

Comparison between Preemptive and Non Preemptive Scheduling

PARAMENTER PREEMPT NON-


IVE PREEMPTIVE
SCHEDUL SCHEDULING
ING

Process can be Process can not be interrupted


Interrupt interrupted in until l it terminates itself or its

between. time is up.

If a process having If a process with long burst time

high priority is running CPU, then later

frequently arrives in coming process with less CPU


Starvation
the ready queue, low burst time may starve.

priority process

maystarve.

Flexibility flexible rigid

Cost cost associated no cost associated

CPU In preemptive It is low in non

Utilization scheduling, preemptive

CPUutilization is scheduling.

high.

III Sem BCA Operating System Unit I- 19


SJR College Department Of Computer Science

Examples of Examples of non-

preemptive preemptive scheduling


Examples
scheduling are are First Come First

Round Robin Serveand Shortest Job

andShortest First

Remaining Time First.

Context Switch

 Whenever an interrupt arrives, the CPU must do a state-save of


the currently running process, then switch into kernel mode to
handle the interrupt, and then do a state- restore of the
interrupted process.
 Similarly, a context switch occurs when the time slice for one
process has expired and a new process is to be loaded from the ready
queue. This will be instigated by a timer interrupt, which will then
cause the current process's state to be saved and the new process's
state to be restored.

Co-operating processes
In the computer system, there are many processes which may be either independent
processes or
cooperating processes that run in the operating system.

A process is said to be independent when it cannot affect or be affected by


any other processes that are running the system. It is clear that any process
which does not share anydata (temporary or persistent) with any another
process then the process independent.

On the other hand, a cooperating process is one which can affect or


affected by any another process that is running on the computer. the
cooperating process is one which shares data with another process.

There are several reasons for providing an environment that allows process

III Sem BCA Operating System Unit I- 20


SJR College Department Of Computer Science

cooperation:

 Information sharing
In the information sharing at the same time, many users may want the same
piece of information(for instance, a shared file) and we try to provide that
environment in which the users are allowed to concurrent access to these types
of resources.
 Computation speedup
When we want a task that our process run faster so we break it into a subtask,
and each subtask will be executing in parallel with another one. It is noticed
that the speedup can be achieved only
if the computer has multiple processing elements (such as CPUs or I/O channels).
 modularity
In the modularity, we are trying to construct the system in such a modular
fashion, in which the system dividing its functions into separate processes.
 Convenience
An individual user may have many tasks to perform at the same time and
the user is able to do his work like editing, printing and compiling.

Thread

It 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 canbe executed parallely by increasing number of threads.

III Sem BCA Operating System Unit I- 21


SJR College Department Of Computer Science

Benefits of Multithreading

1. Responsiveness
2. Resource sharing, hence allowing better utilization of resources.
3. Economy. Creating and managing threads becomes easier.

III Sem BCA Operating System Unit I- 22


SJR College Department Of Computer Science

4. Scalability. One thread runs on one CPU. In Multithreaded


processes, threads can be distributed over a series of processors
to scale.
5. Context Switching is smooth. Context switching refers to the
procedure followed by CPU to change from one task to another.

CPU Scheduling Criteria

Different CPU scheduling algorithms have different properties and the choice
of a particular algorithm depends on the various factors. Many criteria have
been suggested for comparing CPU scheduling algorithms.
The criteria include the following:
1. CPU utilization –
The main objective of any CPU scheduling algorithm is to keep the
CPU as busy as possible. Theoretically, CPU utilization can range from
0 to 100 but in a real-time system, it varies from 40 to 90 percent
depending on the load upon the system.

2. Throughput –
A measure of the work done by CPU is the number of processes being
executed and completed per unit time. This is called throughput. The
throughput may vary depending upon the length or duration of
processes. Eg 10process/Second,5process/1 hour

3. Turnaround time –
For a particular process, an important criteria is how long it takes to
execute that process. The time elapsed from the time of submission of a
process to the time of completion is known as the turnaround time.
Turnaround Time = Waiting Time + Execution Time
4. Waiting time –
A scheduling algorithm does not affect the time required to complete
the process once it starts execution. It only affects the waiting time
of a process i.e. time spent by a process waiting in the ready queue.

5. Response time –
Thus another criteria is the time taken from submission of the

process of request until the first response is produced. This

measure is called response time.

III Sem BCA Operating System Unit I- 23


SJR College Department Of Computer Science

There are various CPU Scheduling algorithms such as-


 First Come First Served (FCFS)
 Shortest Job First (SJF)
 Priority Scheduling
 Round Robin (RR)
 Multi level queue scheduling

1. First Come First Served (FCFS)

In the "First come first serve" scheduling algorithm, as the name suggests,
the process which arrives first, gets executed first, or we can say that the
process which requests theCPU first, gets the CPU allocated first.

First Come First Serve, is just like FIFO(First in First out) Queue
data structure, where thedata element which is added to the queue
first, is the one who leaves the queue first. This is used in Batch
Systems.
It's easy to understand and implement programmatically, using a
Queue data structure, where a new process enters through the tail of
the queue, and the scheduler selects process from the head of the
queue.
A perfect real life example of FCFS scheduling is buying tickets at
ticket counter. Consider the processes P1, P2, P3, P4 given in the
below table, arrives for execution in the same order, with Arrival
Time 0, and given Burst Time, let's find the average waitingtime
using the FCFS scheduling algorithm.

III Sem BCA Operating System Unit I- 24


SJR College Department Of Computer Science

III Sem BCA Operating System Unit I- 25


SJR College Department Of Computer Science

The average waiting time will be 18.75 ms


For the above given proccesses, first P1 will be provided with the CPU resources,

Hence, waiting time for P1 will be 0

P1 requires 21 ms for completion, hence waiting time for P2

will be 21 ms Similarly, waiting time for process P3 will be

execution time of P1 + execution timefor P2, which will be

(21 + 3) ms = 24 ms.
For process P4 it will be the sum of execution times of P1, P2 and P3.

2. Shortest Job First (SJF)

This is the best approach to


minimize waiting time. This is
used in Batch Systems.
It is of two types:
1. Non Pre-emptive
2. Pre-emptive
To successfully implement it, the burst time/duration time of the
processes should be known to the processor in advance, which is
practically not feasible all the time.

This scheduling algorithm is optimal if all the jobs/processes are


available at the same time. (either Arrival time is 0 for all, or Arrival
time is same for all)

Non Pre-emptive Shortest Job First

Consider the below processes available in the ready queue for


execution, with arrival time as 0 for all and given burst times.

III Sem BCA Operating System Unit I- 26


SJR College Department Of Computer Science

As you can see in the GANTT chart above, the process P4 will be picked up
first as it has the shortest burst time, then P2, followed by P3 and at last P1.
We scheduled the same set of processes using the First come first serve
algorithm in the previous tutorial, and got average waiting time to be 18.75
ms, whereas with SJF, the averagewaiting time comes out 4.5 ms.

3. Priority Scheduling Algorithm

the scheduling is done on the basis of priority of the process where the process
which is most urgent is processed first, followed by the ones with lesser
priority in order.
Processes with same priority are executed in FCFS manner.

The priority of process, when internally defined, can be decided based on


memory requirements, time limits ,number of open files, ratio of I/O
burst to CPU burst etc.

III Sem BCA Operating System Unit I- 27


SJR College Department Of Computer Science

Types of Priority Scheduling Algorithm

Priority scheduling can be of two types:


1. Preemptive Priority Scheduling: If the new process arrived at the ready
queue has a
higher priority than the currently running process, the CPU is
preempted, which means the processing of the current process is
stopped and the incoming new process with higher priority gets the
CPU for its execution.
2. Non-Preemptive Priority Scheduling: In case of non-preemptive
priority scheduling algorithm if a new process arrives with a
higher priority than the current running process, the incoming
process is put at the head of the ready queue, which means after the
execution of the current process it will be processed.

Example of Priority Scheduling Algorithm

Consider the below table for processes with their respective CPU burst times and the
priorities.

4. Round Robin Scheduling

A fixed time is allotted to each process, called quantum, for execution.


Once a process is executed for given time period that process is
preemptied and other process executes for given time period.

III Sem BCA Operating System Unit I- 28


SJR College Department Of Computer Science

Context switching is used to save states of preempted processes.

III Sem BCA Operating System Unit I- 29


SJR College Department Of Computer Science

5.Multilevel Queue Scheduling

Another class of scheduling algorithms has been created for situations in


which processes are easily classified into different groups.
For example: A common division is made between foreground(or
interactive) processes and background (or batch) processes. These
two types of processes have different response-time requirements,
and so might have different scheduling needs. In addition,
foreground processes may have priority over background processes.
A multi-level queue scheduling algorithm partitions the ready queue
into several separate queues. The processes are permanently assigned to
one queue, generally based on some property of the process, such as
memory size, process priority, or process type. Each queue has its own
scheduling algorithm.
For example: separate queues might be used for foreground and
background processes. The foreground queue might be scheduled by
Round Robin algorithm, while the background queue is scheduled by
an FCFS algorithm.
In addition, there must be scheduling among the queues, which is

III Sem BCA Operating System Unit I- 30


SJR College Department Of Computer Science

commonly implemented as fixed-priority preemptive scheduling. For


example: The foreground queue may have absolute priority over the
background queue.
Let us consider an example of a multilevel queue-scheduling
algorithm with five queues:

1. System Processes
2. Interactive Processes
3. Interactive Editing Processes
4. Batch Processes
5. Student Processes
Each queue has absolute priority over lower-priority queues. No
process in the batch queue, for example, could run unless the queues
for system processes, interactive processes, and interactive editing
processes were all empty. If an interactive editing process entered the
ready queue while a batch process was running, the batch processwill
be preempted.

III Sem BCA Operating System Unit I- 31

You might also like