chapter-operating-system-class-8
chapter-operating-system-class-8
TABLE OF CONTENTS
Chapter: Operating system
Operating system 02
Function of operating system 02-03
I. Memory management
II. Processor management
III. Device management
IV. File management
V. Other important activities
Types of operating system 03-05
I. Batch OS
II. Distributed OS
III. Multitasking OS
IV. Network OS
V. Real OS
Single and multi user operating system
Applications of OS
Process of OS
Process lifecycle
Scheduler in OS
Comparison among scheduler
Process scheduling of OS
Types of scheduling
Thread
Difference between thread and process
Advantages of thread
1|P a g e
PROCESSOR MANAGEMENT:
In multiprogramming environment, the OS decides
which process gets the processor when and for
Functions of
how much time. This function is called processing
operating system:
2|P a g e
I. Keeps tracks of processor and status of Following are some of the important activities
process. The program responsible for this that an Operating System performs −
task is known as traffic controller. I. Security − By means of password and
II. Allocates the processor (CPU) to a process. similar other techniques, it prevents
unauthorized access to programs and
III. De-allocates processor when a process is data.
no longer required.
II. Control over system performance −
DEVICE MANAGEMENT: Recording delays between request for a
An Operating System manages device service and response from the system.
communication via their respective drivers. It III. Job accounting − Keeping track of time and
does the following activities for device resources used by various jobs and users.
management −
IV. Error detecting aids − Production of
I. Keeps tracks of all devices. Program dumps, traces, error messages, and other
responsible for this task is known as debugging and error detecting aids.
the I/O controller.
V. Coordination between other softwares and
II. Decides which process gets the device users − Coordination and assignment of
when and for how much time. compilers, interpreters, assemblers and
III. Allocates the device in the efficient way. other software to the various users of the
computer systems.
IV. De-allocates devices.
FILE MANAGEMENT: Types of
A file system is normally organized into operating
directories for easy navigation and usage. These system
directories may contain files and other directions.
Following are
An Operating System does the following activities
the types of
for file management −
operating
I. Keeps track of information, location, uses, system.
status etc. The collective facilities are
I. Batch OS
often known as file system.
II. Distributed OS
II. Decides who gets the resources.
III. Multitasking OS
III. Allocates the resources. IV. Network OS
IV. De-allocates the resources V. Real-OS
3|P a g e
Batch OS is the first operating system for I. Failureof one sys tem will not affect the
second-generation computers. This OS does not other systems because all the
directly interact with the computer. Instead, an computers are independent of each
operator takes up similar jobs and groups them other.
together into a batch, and then these batches II. The load on the host system is reduced.
are executed one by one based on the firs t- III. The size of the network is easily scalable
come, first, serve principle. as many computers can be added to
the network.
Advantages of batch OS:
MULTITASKING OS:
I. Execution time taken for similar jobs is
higher. The multitasking OS is also known as the time-
II. Multipleusers can share batch systems. sharing operating system as each task is given
III. Managing large works becomes easy in some time so that all the tasks work efficiently.
batch systems This system provides access to a large number of
users, and each user gets the time of CPU as they
. get in a single system. The tasks performed are
given by a single user or by different users. The
DISTRIBUTED OS:
time allotted to execute one task is called a
quantum, and as soon as the time to execute
A distributed operating system is a recent
one task is completed, the system switches over
advancement in the field of computer
to another task.
technology and is utilized all over the world that
too with great pace. In a distributed OS, various
Advantages of multitasking OS:
computers are connected through a single
communication channel. These independent I. Each task gets equal time for execution.
computers have their memory unit and CPU and II. The idle time for the CPU will be the
are known as loosely coupled systems. The lowest.
system processes can be of different sizes and III. There are very few chances for the
can perform different functions. The major duplication of the software.
benefit of such a type of operating system is that
a user can access files that are not present on his
system but another connected system. In
addition, remote access is available to the
systems connected to this network.
4|P a g e
I. New technologies and hardware can the task. Furthermore, a time limit is always set
easily upgrade the systems. for a specific job, enabling short time delays for
II. Security of the system is managed over
future tasks, which is acceptable. For Example,
servers.
virtual reality, reservation system, etc.
III. Serverscan be accessed remotely from
different locations and systems.
Advantages of real-time OS:
REAL-TIME OS:
I. It provides more output from all the
resources as there is maximum
Real-Time operating systems serve real-time
utilization of systems.
systems. These operating systems are useful II. It provides the best management of
where many events occur in a short time or memory allocation.
III. These systems are always error-free.
certain deadlines, such as real-time simulations.
5|P a g e
Only one task at one time gets schedules different tasks for
Performance
performed performance at any rate.
Graphically
6|P a g e
Coordination between other softwares and users − Coordination and assignment of compilers,
interpreters, assemblers and other software to the various users of the computer systems.
7|P a g e
1 Stack
The process Stack contains the temporary data such as method/function
parameters, return address and local variables.
2 Heap
This is dynamically allocated memory to a process during its run time.
3 Text
This includes the current activity represented by the value of Program
Counter and the contents of the processor's registers.
4 Data
This section contains the global and static variables.
When a process executes, it passes through different states. These stages may differ in different operating
systems, and the names of these states are also not standardized.
In general, a process can have one of the following five states at a time.
8|P a g e
1 Start
This is the initial state when a process is first started/created.
2 Ready
The process is waiting to be assigned to a processor. Ready processes are waiting
to have the processor allocated to them by the operating system so that they can
run. Process may come into this state after Start state or while running it by but
interrupted by the scheduler to assign CPU to some other process.
3 Running
Once the process has been assigned to a processor by the OS scheduler, the
process state is set to running and the processor executes its instructions.
4 Waiting
Process moves into the waiting state if it needs to wait for a resource, such as
waiting for user input, or waiting for a file to become available.
5 Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating system,
it is moved to the terminated state where it waits to be removed from main
memory.
Schedulers
Schedulers are special system software which handle process scheduling in various ways. Their main task is to
select the jobs to be submitted into the system and to decide which process to run. Schedulers are of three types
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
9|P a g e
2 Speed is lesser than short Speed is fastest among Speed is in between both short
term scheduler other two and long term scheduler.
5 It selects processes from pool It selects those processes It can re- introduce the process
and loads them into memory which are ready to execute into memory and execution
for execution can be continued.
A Process Scheduler schedules different processes to be assigned to the CPU based on particular scheduling
algorithms. There are six popular process scheduling algorithms which we are go ing to discuss in this chapter .
These algorithms are either non-preemptive or preemptive. Non-preemptive algorithms are designed so that
once a process enters the running state, it cannot be preempted until it completes its allotted time, whereas the
preemptive scheduling is based on priority where a scheduler may preempt a low priority running process
anytime when a high priority process enters into a ready state.
10 | P a g e
P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13
P0 0 5 0
11 | P a g e
P1 1 3 5
P2 2 8 14
P3 3 6 8
P0 0-0=0
P1 5-1=4
P2 14 - 2 = 12
P3 8-3=5
Priority Scheduling
Priority scheduling is a more general case of SJF, in which each job is assigned a priority and the job
with the highest priority gets scheduled first. ( SJF uses the inverse of the next expected burst time as its
priority - The smaller the expected burst, the higher the priority. )
Note that in practice, priorities are implemented using integers within a fixed range, but there is no
agreed-upon convention as to whether "high" priorities use large numbers or small numbers. This book
uses low number for high priorities, with 0 being the highest possible priority.
For example, the following Gantt chart is based upon these process burst times and priorities, and yields
an average waiting time of 8.2 ms:
P1 10 3
P2 1 1
12 | P a g e
P3 2 4
P4 1 5
P5 5 2
Priorities can be assigned either internally or externally. Interna l priorities are assigned by the OS using
criteria such as average burst time, ratio of CPU to I/O activity, system resource use, and other factors
available to the kernel. External priorities are assigned by users, based on the importance of the job, fees
paid, politics, etc.
Priority scheduling can be either preemptive or non-preemptive.
Priority scheduling can suffer from a major problem known as indefinite blocking, or starvation, in
which a low-priority task can wait forever because there are always so me other jobs around that have
higher priority.
o If this problem is allowed to occur, then processes will either run eventually when the system
load lightens ( at say 2:00 a.m. ), or will eventually get lost when the system is shut down or
crashes. ( There are rumors of jobs that have been stuck for years. )
o One common solution to this problem is aging, in which priorities of jobs increase the longer
they wait. Under this scheme a low-priority job will eventually get its priority raised high enough
that it gets run.
P0 (0 - 0) + (12 - 3) = 9
P1 (3 - 1) = 2
P3 (9 - 3) + (17 - 12) = 11
13 | P a g e
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.
Given: Table of processes, and their Arrival time, Execution time, and priority. Here we are considering 1 is
the lowest priority.
Process Arrival Time Execution Time Priority Service Time
P0 0 5 1 0
P1 1 3 2 11
P2 2 8 1 14
P3 3 6 3 5
P0 0-0=0
P1 11 - 1 = 10
P2 14 - 2 = 12
P3 5-3=2
14 | P a g e
What is Thread?
A thread is a flow of execution through the process code, with its own program counter that keeps track of
which instruction to execute next, system registers which hold its current working variables, and a stack which
contains the execution history.
2 Process switching needs interaction with Thread switching does not need to
operating system. interact with operating system.
3 In multiple processing environments, All threads can share same set of open
each process executes the same code but files, child processes.
has its own memory and file resources.
4 If one process is blocked, then no other While one thread is blocked and waiting,
process can execute until the first process a second thread in the same task can run.
is unblocked.
5 Multiple processes without using threads Multiple threaded processes use fewer
use more resources. resources.
6 In multiple processes each process One thread can read, write or change
operates independently of the others. another thread's data.
Advantages of Thread
Threads minimize the context switching time.
Use of threads provides concurrency within a process.
Efficient communication.
It is more economical to create and context switch threads.
Threads allow utilization of multiprocessor architectures to a greater scale and efficiency.
15 | P a g e
16 | P a g e