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

chapter-operating-system-class-8

Uploaded by

maitisuvroneil
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)
52 views

chapter-operating-system-class-8

Uploaded by

maitisuvroneil
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/ 17

lOMoARcPSD|50446412

Chapter Operating system class 8

Data structures (Sir Syed University of Engineering and Technology)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Sudeshna Saha ([email protected])
lOMoARcPSD|50446412

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

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

OPERATING SYSTEM Following are some of important functions of an


operating System.
An Operating
System (OS) is I. Memory Management
an interface II. Processor Management
between III. Device Management
computer user IV. File Management
and computer V. Security
hardware. An, VI. Control over system performance
operating system is a software which performs all VII. Job accounting
the basic tasks like file management, memory VIII. Error detecting aids
management, process management, handling
input and output, and controlling peripheral IX. Coordination between other software and
devices such as disk drives and printers. users

Some popular Operating Systems include Linux


MEMORY MANAGEMENT:
Operating System, Windows Operating System,
Memory management refers to management of
VMS, OS/400, AIX, z/OS, etc.
Primary Memory or Main Memory. Main memory
OPERATING SYSTEM: is a large array of words or bytes where each
word or byte has its own address.
An operating system is a program that acts as an
Main memory provides a fast storage that can be
interface between the user and the computer accessed directly by the CPU. For a program to be
hardware and controls the execution of all kinds of executed, it must in the main memory. An
programs. 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.
 De-allocates the memory when a process
no longer needs it or has been terminated.

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

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

scheduling. An Operating System does the


following activities for processor management. OTHER IMPORTANT ACTIVITIES:

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

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

BATCH OS: Advantages of distributed OS:

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

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

NETWORK OS: Of such applications are very strict. Such


systems are built for life-saving equipment like
Network operating systems are the systems that parachutes and airbags, which immediately
run on a server and manage all the networking need to be in action if an accident happens.
functions. They allow sharing of various files,
applications, printers, security, and other Soft real-time OS:
networking functions over a small network of
computers like LAN or any other private The soft real-time OS is the operating system for
network. In the network OS, all the users are applications where time constraint is not very
aware of the configurations of every other user
strict.
within the network, which is why network
operating systems are also known as tightly
coupled systems. In a soft real-time system, an important task is
prioritized over less important tasks, and this
Advantages of network OS:
priority remains active until the completion of

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.

Types of the real-time operating system are:

Hard real-time OS:

The hard-real-time OS is the operating system


for mainly the applications in which the slightest
delay is also unacceptable. The time cons traints

5|P a g e

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

SINGLE USER AND MULTI USER OPERATING

Basis of Multi-User Operating


Single User Operating System
Distinction System

A mode where the user has a


A mode where the user has a
multipurpose computer screen
screen where only one
to run the program and the
Definition program runs and different
operating system boots into a
people within the environment
single super user that controls
have access to various devices.
all the activities.

A super user gets all the powers


Each entity has control over
of maintaining the system and
Super User their working hence no
making changes to ensure the
requiring of super user.
system runs smoothly.

Only one task at one time gets schedules different tasks for
Performance
performed performance at any rate.

Graphically

Applications of Operating System


Following are some of the important activities that an Operating System performs −
 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.

6|P a g e

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

 Coordination between other softwares and users − Coordination and assignment of compilers,
interpreters, assemblers and other software to the various users of the computer systems.

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
Process
 A process is basically a program in execution. The execution of a process must progress in a sequential
fashion.
 A process is defined as an entity which represents the basic unit of work to be implemented in the
system.
 To put it in simple terms, we write our computer programs in a text file and when we execute this
program, it becomes a process which performs all the tasks mentioned in the program.
 When a program is loaded into the memory and it becomes a process, it can be divided into four
sections ─ stack, heap, text and data. The following image shows a simplified layout of a process inside
main memory −

7|P a g e

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

S.N. Component & Description

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.

Process Life Cycle

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

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

S.N. State & Description

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

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

The Purpose of a Scheduling algorithm


Here are the reasons for using a scheduling algorithm:

 The CPU uses scheduling to improve its efficiency.


 It helps you to allocate resources among competing processes.
 The maximum utilization of CPU can be obtained with multi-programming.
 The processes which are to be executed are in ready queue.

Comparison among Scheduler


S.N. Long-Term Schedule r Short-Term Scheduler Medium-Term Scheduler

1 It is a job scheduler It is a CPU scheduler It is a process swapping


scheduler.

2 Speed is lesser than short Speed is fastest among Speed is in between both short
term scheduler other two and long term scheduler.

3 It controls the degree of It provides lesser control It reduces the degree of


multiprogramming over degree of multiprogramming.
multiprogramming

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


in time sharing system sharing system systems.

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 .

 First-Come, First-Served (FCFS) Scheduling


 Shortest-Job-Next (SJN) Scheduling
 Priority Scheduling
 Shortest Remaining Time
 Round Robin(RR) Scheduling

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

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

First Come First Serve (FCFS)


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

Wait time of each process is as follows −

Process Wait Time : Service Time - Arrival Time

P0 0-0=0

P1 5-1=4

P2 8-2=6

P3 16 - 3 = 13

Average Wait Time: (0+4+6+13) / 4 = 5.75


Shortest Job Next (SJN)
 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 processer should know in advance how much time process will take.
Given: Table of processes, and their Arrival time, Execution time

Process Arrival Time Execution Time Service Time

P0 0 5 0

11 | P a g e

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

P1 1 3 5

P2 2 8 14

P3 3 6 8

Waiting time of each process is as follows −

Process Waiting Time

P0 0-0=0

P1 5-1=4

P2 14 - 2 = 12

P3 8-3=5

Average Wait Time: (0 + 4 + 12 + 5)/4 = 21 / 4 = 5.25

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:

Process Burst Time Priority

P1 10 3

P2 1 1
12 | P a g e

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

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.

Round Robin Scheduling


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

Wait time of each process is as follows −

Process Wait Time : Service Time - Arrival Time

P0 (0 - 0) + (12 - 3) = 9

P1 (3 - 1) = 2

P2 (6 - 2) + (14 - 9) + (20 - 17) = 12

P3 (9 - 3) + (17 - 12) = 11

13 | P a g e

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

Average Wait Time: (9+2+12+11) / 4 = 8.5

Priority Based Scheduling

 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

Waiting time of each process is as follows −

Process Waiting Time

P0 0-0=0

P1 11 - 1 = 10

P2 14 - 2 = 12

P3 5-3=2

Average Wait Time: (0 + 10 + 12 + 2)/4 = 24 / 4 = 6

14 | P a g e

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

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.

Difference between Process and Thread

S.N. Process Thread

1 Process is heavy weight or resource Thread is light weight, taking lesser


intensive. resources than a process.

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

Downloaded by Sudeshna Saha ([email protected])


lOMoARcPSD|50446412

16 | P a g e

Downloaded by Sudeshna Saha ([email protected])

You might also like