0% found this document useful (0 votes)
10 views110 pages

R22_OS_Unit-I

The document provides an introduction to operating systems (OS), detailing their functions, objectives, history, and various types, including batch, multiprogramming, multiprocessing, time-sharing, multitasking, distributed, real-time, and parallel operating systems. It emphasizes the OS as a crucial interface between hardware and users, managing resources and enabling efficient operation. Additionally, it outlines the advantages and disadvantages of each OS type, highlighting their applications and significance in computing.

Uploaded by

amreen2825
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)
10 views110 pages

R22_OS_Unit-I

The document provides an introduction to operating systems (OS), detailing their functions, objectives, history, and various types, including batch, multiprogramming, multiprocessing, time-sharing, multitasking, distributed, real-time, and parallel operating systems. It emphasizes the OS as a crucial interface between hardware and users, managing resources and enabling efficient operation. Additionally, it outlines the advantages and disadvantages of each OS type, highlighting their applications and significance in computing.

Uploaded by

amreen2825
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/ 110

Operating Systems

UNIT-1
CH-1: OPERATING SYSTEM – I NTRODUCTION
CH-2: PROCESS

PREPARED BY GSK
Ch-1:
Operating System –
Introduction

PREPARED BY GSK
What is Operating System?
❖An Operating System (OS) is a software that acts as an interface
between computer hardware components and the user.
❖It 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.
❖An operating system is software that enables applications to
interact with a computer's hardware. The software that contains the
core components of the operating system is called the kernel.

PREPARED BY GSK
What is Operating System? Contd. .

PREPARED BY GSK
What is Operating System? Contd. .
➢Generally, a Computer System consists of the following components:
➢Application Software are the software which users use directly to perform
different activities. These software are simple and easy to use like Browsers,
Word, Excel, different Editors, Games etc. These are usually written in high-
level languages, such as Python, Java and C++.
➢System Software are the software which are more complex in nature. These
software are usually written in low-level languages like assembly language
and includes Operating Systems (Microsoft Windows, macOS, and Linux),
Compiler, and Assembler etc.
➢Computer Hardware includes Monitor, Keyboard, CPU, Disks, Memory, etc.

PREPARED BY GSK
❖If we consider a Computer Hardware is
body of the Computer System, then we can
In simple words.. say an Operating System is its soul which
brings it alive ie. operational.
The operating system is a soul to the
computer.

❖We can never use a Computer System if it


does not have an Operating System installed
on it.

PREPARED BY GSK
Objectives of OS

The primary goals of an operating system are as follows:


Convenience – An operating system improves the use of a machine.
Operating systems enable users to get started on the things they
wish to complete quickly without having to cope with the stress of
first configuring the system.
Efficiency – An operating system enables the efficient use of
resources. This is due to less time spent configuring the system.

PREPARED BY GSK
Objectives of OS Contd..

•Ability to evolve – An operating system should be designed in such a


way that it allows for the effective development, testing, and
introduction of new features without interfering with service.
•Management of system resources – It guarantees that resources are
shared fairly among various processes and users.

PREPARED BY GSK
History of OS
❖Operating systems were first developed in the late 1950s to
manage tape storage
❖In the mid-1960s, operating systems started to use disks
❖In the late 1960s, the first version of the Unix OS was
developed
❖The first OS built by Microsoft was DOS. It was built in 1981.
❖The Windows OS first came to existence in 1985 when a GUI
was created and paired with MS-DOS.

PREPARED BY GSK
Operating System with Market Share

PREPARED BY GSK
OS Structure…
Generic architecture diagram of an
Operating System

PREPARED BY GSK
PREPARED BY GSK
1. Batch Operating Systems
➢In the 1970s, Batch processing was very popular. In this technique,
similar types of jobs were batched together and executed in time.
People were used to having a single computer which was called a
mainframe.
➢In Batch operating system, operator has to collect the jobs and
submit jobs to the system for the execution.
➢The system put all of the jobs in a queue on the basis of first come
first serve and then executes the jobs one by one. The users collect
their respective output when all the jobs get executed.

PREPARED BY GSK
➢ In a Batch OS, users prepare tasks as jobs on offline devices like punch cards, which
are submitted to the computer operator.
➢ Similar job punch cards are grouped and processed as a batch to improve efficiency.
➢ Jobs include programs, input data, and control instructions.

PREPARED BY GSK
➢ The purpose of this operating system was mainly to transfer control from one job to
another as soon as the job was completed.
➢ It contained a small set of programs called the resident monitor that always resided in
one part of the main memory.
➢ The remaining part is used for servicing jobs.
PREPARED BY GSK
➢The batch processing system takes less time for
the execution of all the jobs.
Advantages
➢All jobs in a batch operating system are
Batch OS
repeated without the user's permission.

➢It is suitable for large jobs. It can easily manage


large jobs efficiently.

PREPARED BY GSK
▪The computer operator must be trained and provided
ample knowledge for handling the batch processing
operating system

▪It takes more time for debugging.

Disadvantages ▪The users do not have direct interaction with the system
Batch OS Batch Processing is not suitable for jobs that are dependent
on the user's input. If a job requires the input of two
numbers from the console, then it will never get it in the
batch processing scenario since the user is not present at
the time of execution

▪If a job enters an infinite loop, other jobs might have to wait
for an unknown period of time. ( Called Starvation)

▪Failure of one job impacts the execution of other jobs.


PREPARED BY GSK
2. Multiprogramming Operating System
❖Multiprogramming is an extension
to batch processing where the CPU is
always kept busy.
❖Each process needs two types of
system time: CPU time and IO time.
❖In a multiprogramming
environment, when a process does its
I/O, The CPU can start the execution
of other processes. Therefore,
multiprogramming improves the Different programs in memory are present
simultaneously, and the CPU switches between
efficiency of the system. them for execution.

PREPARED BY GSK
2. Multiprogramming Operating System
Contd…

Advantages of Multiprogramming OS: Disadvantages of Multiprogramming


OS:
❖It requires CPU scheduling and
❖Throughout the system, it increased memory management.
as the CPU always had one program to
execute. ❖It can cause long waiting time for
some jobs.
❖Response time can also be reduced.
❖It can cause heat-up issue.

Example for Multiprogramming: On Android, iOS, and other mobile operating systems on the phone,
one can search on Google while sending and receiving text messages on what’s the app at one time.
This means these two programs are in the memory, and the CPU is switching between them.

PREPARED BY GSK
3. Multiprocessing Operating System

❖A multiprocessing operating system is


defined as a type of operating system
that makes use of more than one CPU
to improve performance.
❖Multiple processors work parallelly in
multi-processing operating systems to
perform the given task.
❖All the available processors are
connected to peripheral devices,
computer buses, physical memory, and
clocks.

PREPARED BY GSK
❖Multi-processing operating system consists of multiple
CPUs. Each CPU is connected to the main memory.
Working of
❖The task to be performed is divided among all the
Multi-Processing processors.
Operating System
❖For faster execution and improved performance, each
processor is assigned a specific task.
❖Once all the tasks of each processor are completed they
are compiled together in order to produce a single output.
❖The allocation of resources for each processor is handled
by the operating system.
❖This process results in better utilization of the available
resources and improved performance.

PREPARED BY GSK
3. Multiprocessing Operating System
Contd…

Advantages of Multiprocessing OS: Disadvantages of Multiprocessing OS:


❖Increased reliability: Due to the ❖They are difficult to implement,
multiprocessing system, processing process scheduling, and resource
tasks can be distributed among several allocation since we involve more than
processors. This increases reliability as one processor.
if one processor fails, the task can be
given to another processor for ❖They are complex and require
completion. specialized knowledge.
❖Increased throughput: As several ❖All the software may not be
processors increase, more work can be compatible with multiprocessing.
done in less time.

PREPARED BY GSK
4. Time-Sharing Operating System

❖In the Time Sharing operating system,


computer resources are allocated in a
time-dependent fashion to several users
simultaneously. Thus it helps to provide a
large number of user's direct access to the
main computer.
❖It is a logical extension of
multiprogramming.
❖In time-sharing, the CPU is switched
among multiple programs given by
different users on a scheduled basis.

PREPARED BY GSK
4. Time-Sharing Operating System
Contd..

❖Time sharing is a method that allows multiple users to share resources at


the same time.
❖Multiple users in various locations can use a specific computer system at a
time.
❖Several terminals are attached to a single dedicated server. Therefore, the
processor executes multiple user programs simultaneously.
❖In other words, the processor time is shared between multiple users at a
time.
❖The processor allows each user program to execute for a small time
quantum.

PREPARED BY GSK
4. Time-Sharing Operating System contd..

Advantages of Time Sharing Operating Disadvantages of Time Sharing


System: Operating System:
❖The time-sharing operating system ❖It uses a lot of resources.
provides effective utilization and
sharing of resources. ❖Hardware with high quality is
required.
❖This system reduces CPU idle and
response time. ❖Security and integrity of user
programs loaded in memory and data
need to be maintained as many users
access the system at the same time.
(No Security)

PREPARED BY GSK
5. Multitasking Operating systems
➢A multitasking operating system (OS) is a type
of multiprogramming OS that supports
multiple tasks or processes to run
concurrently
➢Single user’s multiple tasks are being
executed concurrently.
➢It is a logical extension of multiprogramming
➢For example – A mobile phone with multiple
apps running in the background while the user
interacts with another app in the foreground.

PREPARED BY GSK
Time sharing vs Multitasking
TIME SHARING MULTI TASKING
While time sharing allows multiple Multitasking allows a single user’s
users to use a computer system at a multiple tasks or processes to use a
time computer system at a time

PREPARED BY GSK
6. Distributed Operating System

❖The Distributed Operating system


is not installed on a single
machine, it is divided into parts,
and these parts are loaded on
different machines.
❖A part of the distributed
Operating system is installed on
each machine to make their
communication possible.

PREPARED BY GSK
6. Distributed Operating System Contd..

❖Distributed Operating systems are much more complex and large,


because they also have to take care of varying networking protocols.
❖Sometimes it is also called loosely coupled systems because in
which each processor has its own local memory and processing
units.

PREPARED BY GSK
6. Distributed Operating System contd..

Advantages of Distributed Disadvantages of Distributed


Operating System: Operating System:
❖The distributed operating system ❖Protocol overhead can dominate
provides sharing of resources. computation cost.
❖This type of system is
fault-tolerant.

PREPARED BY GSK
Types of Distributed Operating System

I) Client-Server System:
❖This type of system requires
the client to request a
resource, after which the
server gives the requested
resource.
❖When a client connects to a
server, the server may serve
multiple clients at the same
time.
PREPARED BY GSK
Types of Distributed Operating System

I) Client-Server System Contd..:


❖Client-Server Systems are also referred to as "Tightly Coupled
Operating Systems".
❖This system is primarily intended for multiprocessors and
homogenous multicomputer.
❖Client-Server Systems function as a centralized server since they
approve all requests issued by client systems.

PREPARED BY GSK
Types of Distributed Operating System

II)Peer-to-Peer Network System:


❖This model does not distinguish
between clients and servers;
❖Each node acts as both a client and
server.
❖Every node in a peer-to-peer
network has the ability to request and
provide service.
❖A node is also called a peer.

PREPARED BY GSK
Types of Distributed Operating System

Peer-to-Peer Network Example


❖One of the most well-known peer-to-peer networks is torrent. All
computer in this kind of network is linked to the internet, allowing
users to download resources shared by any one computer.
❖The local area network (LAN), which is typically preferred by small
workplaces for the purpose of resource sharing, is another
frequently used example of the peer-to-peer network.

PREPARED BY GSK
7. Real Time Operating System

❖Let’s understand Real Time Operating System with real life


example:
❖- Suppose a person is driving a car on a highway at a speed of 80
km per hour. Now, unfortunately the car meets with an accident.
Fortunately, the airbag deployed at the right time and saved the life
of the driver.
❖- So, we see that airbag is a very good feature in a car which can
save a life someday. But, what would have happened if the airbag
would have deployed a few seconds late?

PREPARED BY GSK
7. Real Time Operating System Contd..

❖In Real-Time Systems, each job carries a certain deadline within


which the job is supposed to be completed, otherwise, the huge loss
will be there, or even if the result is produced, it will be completely
useless.
❖The Application of a Real-Time system exists in the case of military
applications, if you want to drop a missile, then the missile is
supposed to be dropped with a certain precision.

PREPARED BY GSK
7. Real Time Operating System Contd..

RTOS CAN BE CLASSIFIED INTO THREE TYPES:


❖Hard RTOS: These types of RTOS strictly adhere to the deadline
associated with the tasks.
❖Missing on a deadline can have catastrophic affects.
❖The air-bag example we discussed is example of a hard RTOS as
missing a deadline there could cause a life

PREPARED BY GSK
7. Real Time Operating System Contd..

❖FIRM RTOS: These types of RTOS are also required to adhere to the
deadlines because missing a deadline may not cause a catastrophic
affect but could cause undesired affects, like a huge reduction in
quality of a product which is highly undesired.
❖Soft RTOS: In these type of RTOS, missing a deadline is acceptable.
For example On-line Databases.

PREPARED BY GSK
8. Parallel Operating Systems
❖Parallel Operating Systems
help speed up the processing
time by dividing the task into
multiple sub-tasks or sub-
processes.
❖This way, numerous processors
can deal with various tasks
simultaneously.

PREPARED BY GSK
8. Parallel Operating Systems Contd..
❖It can be achieved using various processors in a single system.
❖Also, such systems can be used when multiple applications are to be
run simultaneously without interfering with each other.
❖A parallel operating system has many applications, such as database
and mining, various engineering fields, graphics, etc.
❖Some examples of parallel operating systems are
Linux with support for SMP (Symmetric Multi-Processing)
Windows Server for enterprise parallel processing

PREPARED BY GSK
Parallel Systems:
vs Distributed Systems:
Parallel Systems:
Definition: Parallel systems are designed to speed up program execution
by dividing programs into multiple fragments and processing these
fragments simultaneously.

Distributed Systems:
Definition: Distributed systems consist of multiple computers connected
by a network, where applications run on different computers.

PREPARED BY GSK
Functions of Operating System

1. Memory Management:
❖It is the management of the main or primary memory.
❖Whatever program is executed, it has to be present in the main
memory. Main memory is a quick storage area that may be accessed
directly by the CPU.
❖When the program is completed, the memory region is released and can
be used by other programs. Therefore, there can be more than one
program present at a time. Hence, it is required to manage the memory.

PREPARED BY GSK
Functions of Operating System

1. Memory Management:
As part of the memory management he operating system
❖Allocates and deallocates the memory.
❖Keeps a record of which part of primary memory is used by whom
and how much.
❖Distributes the memory while multiprocessing

PREPARED BY GSK
Functions of Operating System

2. Processor Management/Scheduling
❖Every software that runs on a computer, whether in the
background or in the frontend, is a process. Processor management
is an execution unit in which a program operates.
❖The operating system determines the status of the processor and
processes, selects a job and its processor, allocates the processor to
the process, and de-allocates the processor after the process is
completed.

PREPARED BY GSK
Functions of Operating System

2. Processor Management/Scheduling
❖When more than one process runs on the system the OS decides
how and when a process will use the CPU. Hence, the name is also
CPU Scheduling.
The OS:
❖Allocates and deallocates processor to the processes.
❖Keeps record of CPU status.

PREPARED BY GSK
Functions of Operating System

3. Device Management:
❖An operating system regulates device connection using drivers. The
processes may require devices for their use. This management is done by
the OS.
The OS:
❖Allocates and deallocates devices to different processes.
❖Keeps records of the devices.
❖Decides which process can use which device for how much time.

PREPARED BY GSK
Functions of Operating System

4. File Management
❖The operating system manages resource allocation and de-
allocation.
❖It specifies which process receives the file and for how long.
❖It also keeps track of information, location, uses, status, and so on.
❖ These groupings of resources are referred to as file systems. The
files on a system are stored in different directories

PREPARED BY GSK
Functions of Operating System

4. File Management
The OS:
❖Keeps records of the status and locations of files.
❖Allocates and deallocates resources.
❖Decides who gets the resources.

PREPARED BY GSK
Functions of Operating System

5. Storage Management
❖Storage management is a procedure that allows users to maximize
the utilization of storage devices.
❖The operating system is in charge of storing and accessing files. The
creation of files, the creation of directories, the reading and writing
of data from files and directories, as well as the copying of the
contents of files and directories from one location to another are all
included in storage management.

PREPARED BY GSK
Functions of Operating System

5. Storage Management
The OS uses storage management for:
❖Improving the performance of the data storage resources.
❖It optimizes the use of various storage devices.
❖Assists businesses in storing more data on existing hardware,
speeding up the data retrieval process, preventing data loss.

PREPARED BY GSK
Components of Operating System

❖An operating system is a large and complex system that can only be created by
partitioning into small parts. These pieces should be a well-defined part of the
system, carefully defining inputs, outputs, and functions.

❖Although Windows, Mac, UNIX, Linux, and other OS do not have the same
structure, most operating systems share similar OS system components, such as
file, memory, process, I/O device management.

❖The components of an operating system play a key role to make a variety of


computer system parts work together.
PREPARED BY GSK
1. Process Management:
➢ The process management component is a
procedure for managing many processes
running simultaneously on the operating
system.
➢ Every running application program has one or
more processes associated with them.
➢ Process management keeps processes running
efficiently. It also uses memory allocated to
them and shutting them down when needed.

PREPARED BY GSK
Functions of process management:
❖ Process creation and deletion.
❖ Suspension and resumption.
❖ Synchronization process
❖ Communication process

NOTE: OS facilitates an exchange of


information between processes
executing on the same or different
systems.

PREPARED BY GSK
2. File Management:
File is used to store related data permanently.

Function of file management:


The operating system has the following important
activities in connection with file management:
❖ File and directory creation and deletion.
❖ For manipulating files and directories.
❖ Mapping files onto secondary storage.
❖ Backup files on stable storage media.

PREPARED BY GSK
3. Main Memory management
Functions for Memory Management:
❖ It helps you to keep track of primary memory.
❖ Determine what part of it are in use by whom, what
part is not in use.
❖ In a multiprogramming system, the OS decides which
process will get memory and how much.
❖ Allocates the memory when a process requests. It Main Memory management
also de-allocates the memory when a process no
longer requires or has been terminated.

PREPARED BY GSK
4. Secondary-Storage Management:
❑ The most important task of a computer system is to execute programs. These programs help
you to access the data from the main memory during execution.
❑ This memory of the computer is very small to store all data and programs permanently. The
computer system offers secondary storage to back up the main memory.
Functions of Secondary storage management:
❖ Storage allocation
❖ Free space management
❖ Disk scheduling

PREPARED BY GSK
5. I/O Device Management:
Functions of I/O management
❖ It offers a buffer caching system
❖ It provides drivers for particular hardware devices.

NOTE: The user's program can't execute I/O


operations directly. The operating system should
provide some medium to perform this.

PREPARED BY GSK
6. Security Management:
➢ The various processes in an operating system need to be secured
from other activities. Therefore, various mechanisms can ensure
those processes that want to operate files, memory CPU, and other
hardware resources should have proper authorization from the
operating system.
➢ Security refers to a mechanism for controlling the access of programs,
processes, or users to the resources.

PREPARED BY GSK
7. Command Interpreter System:

❖ One of the most important components of


an operating system is its command
interpreter.
❖ The command interpreter is the primary
interface between the user and the rest of
the system.
❑ The command-line interpreter
❑ The shell (in UNIX), and so on.

PREPARED BY GSK
What is a Kernel?

❖The kernel is the central component of a computer operating systems. The only
job performed by the kernel is to the manage the communication between the
software and the hardware.
❖Kernel is the innermost part of an operating system, a shell is the outermost
one.

PREPARED BY GSK
System Calls
❖ Dual-mode operation provides a layer of protection between user programs and
the operating system
❖ User Mode: In this mode, execution is done on behalf of the user.
❖ Monitor/Kernel-Mode: In this mode, execution is done on behalf of OS.
❖ System calls are the interface between a user program and the operating
system, allowing the user program to request services from the operating
system. They provide a way for the user-level processes to communicate with
the kernel.

PREPARED BY GSK
How Does the System Call Work?
User need special resources :
❖Sometimes programs need to do some
special things which can’t be done
without the permission of OS like
reading from a file, writing to a file ,
getting any information from the
hardware or requesting a space in
memory.

PREPARED BY GSK
How Does the System Call Work? Contd…

❖Program makes a system call request : There are special predefined


instruction to make a request to the operating system. These instruction are
nothing but just a “system call”. The program uses these system calls in its code
when needed.

❖Operating system sees the system call : When the OS sees the system call then
it recognizes that the program need help at this time so it temporarily stop the
program execution and give all the control to special part of itself called ‘Kernel’
Now ‘Kernel’ solve the need of program.

PREPARED BY GSK
How Does the System Call Work? Contd..
•Operating system performs the operations : Now the operating
system perform the operation which is requested by program .
Example : reading content from a file etc.

•Operating system give control back to the program : After


performing the special operation, OS give control back to the
program for further execution of program .

PREPARED BY GSK
Types of System Calls

PREPARED BY GSK
Types of System Calls Contd..
1. Process Control:

❖Process control is the system call that is used to handle the


processes.

❖Some process control examples include creating, load, abort, end,


execute the process, terminate the process, etc.

PREPARED BY GSK
Types of System Calls Contd..
2. Device Management:

❖These system calls handle the management of devices attached to the


computer, such as printers, scanners, and storage devices.

❖For Example the system calls related to printer enable the OS to manage print
jobs and interact with printers for tasks such as queuing, pausing, and cancelling
print jobs. System calls related to scanners facilitate the communication
between the OS and scanning devices for document scanning.

PREPARED BY GSK
Types of System Calls Contd..
3. Information Maintenance:
❖Information maintenance system calls used to maintain (System)
information. There are some examples of information maintenance,
including getting system data, set time or date, get time or date etc.
❖These system calls ensure the accuracy and consistency of data stored in
the system, preventing corruption or loss.
❖They manage access controls and encryption, safeguarding sensitive
information from unauthorized access and potential breaches.

PREPARED BY GSK
Types of System Calls Contd..
File Management:
❖File management system calls allow the creation and deletion of
files and directories.
❖These system calls handle the setting and modification of file
access permissions.
❖System calls for file management are also responsible for modifying
file attributes such as ownership and timestamps.

PREPARED BY GSK
Types of System Calls Contd..
Communication:
❖Communication is a system call that is used for communication.
There are some examples of communication, including create the
communication connection, delete communication connections,
send the message through the communication media, receive
messages, etc.
❖Allows processes to communicate via phone-like conversations.
❖Enables processes to exchange messages through electronic mail.
❖Facilitates real-time video communication between processes.
PREPARED BY GSK
Examples of Windows and Unix system calls
Process Windows Unix
CreateProcess() fork()
Process Control ExitProcess() exit()
WaitForSingleObject() wait()
CreateFile() open()
File Manipulation ReadFile() read()
WriteFile() write()
CloseHandle() close()
SetConsoleMode() ioctl() (input output control)
Device Management ReadConsole() read()
WriteConsole() write()
GetCurrentProcessID() getpid()
Information Maintenance SetTimer() alarm()
Sleep() sleep()
CreatePipe() pipe()
Communication CreateFileMapping() shmget()
MapViewOfFile() mmap()

PREPARED BY GSK
Chapter-2
Process

PREPARED BY GSK
What is 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

PREPARED BY GSK
Difference between Program and Process
Program Process
Program contains a set of instructions designed
Process is an instance of an executing program.
to complete a specific task.

Program is a passive entity as it resides in the Process is a active entity as it is created during
secondary memory. execution and loaded into the main memory.

Program exists at a single place and continues Process exists for a limited span of time as it
to exist until it is deleted. gets terminated after the completion of task.

Program is a static entity. Process is a dynamic entity.

In addition to program data, a process also


Program has two logical components: code and
requires additional information required for
data.
the management and execution.

PREPARED BY GSK
Process in Memory
A process resides in memory through following section i.e.
1) Stack, 2) Heap, 3) Data and 4) Text
❖Stack section contains local variable
❖Data section contains global variable
❖Text section contains code or instruction.
❖Heap section contains memory which will be Dynamically allocated
during runtime.

PREPARED BY GSK
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.

PREPARED BY GSK
Start/new/born:
❖ This is the initial state when a process is first started/created.
❖ When the request is made by the user, the process is created
❖ The process resides in secondary memory through a queue named as job queue or
job pool.

PREPARED BY GSK
Process Life Cycle
Cont. .
Ready:
❖ Out of total newly created processes, specified processes are selected and
copied to temporary memory or main memory.
❖ In main memory they resides in a queue named as ready queue.
❖ The process is waiting to be assigned to a processor.
❖ 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.

PREPARED BY GSK
Process Life Cycle
Cont. .
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.

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.

PREPARED BY GSK
Process Life Cycle
Cont. .
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.
Sometimes operating system terminates the process due to the following
reasons.
❖Exceeding the time limit
❖ Input/output failure

PREPARED BY GSK
Process Control Block (PCB)
❖ A Process Control Block is a data structure maintained by the
Operating System for every process. The PCB is identified by an
integer process ID (PID). A PCB keeps all the information
needed to keep track of a process

❖ The architecture of a PCB is completely dependent on


Operating System and may contain different information
in different operating systems. Here is a simplified diagram
of a PCB

❖ The PCB is maintained for a process throughout its


lifetime, and is deleted once the process terminates.

PREPARED BY GSK
Process Control Block (PCB) Contd..

Process State:
The current state of the process i.e., whether it is ready, running, waiting,
or whatever.
Process privileges:
This is required to allow/disallow access to system resources.
Process ID:
Unique identification for each of the process in the operating system.

PREPARED BY GSK
Process Control Block (PCB)
Cont. .
Pointer:
A pointer to parent process.
Program Counter:
Program Counter is a pointer to the address of the next instruction to be
executed for this process.
CPU registers:
Various CPU registers where process need to be stored for execution for
running state.

PREPARED BY GSK
Process Control Block (PCB)
Cont. .
CPU Scheduling Information:
Process priority and other scheduling information which is required to
schedule the process.
Accounting information:
This includes the amount of CPU used for process execution, time limits,
execution ID etc.
I/O status information:
This includes a list of I/O devices allocated to the process.

PREPARED BY GSK
Process Scheduling

❖The objective of multiprogramming is to have some process running at


all times, to maximize CPU utilization.
❖The objective of time sharing is to switch the CPU among processes so
frequently that users can interact with each program while it is running.
❖ This purpose can be achieved by keeping the CPU busy at all the times.
❖ So, when two or more processes compete for the CPU at the same
time, a choice has to be made.
❖ This procedure of determining the next process to be executed on the
CPU is called as Process Scheduling.

PREPARED BY GSK
Process Scheduling Contd..

❖The module of the operating system that makes process scheduling


decision is called as Scheduler.

❖ Process scheduling consists of three sub functions:

❑I. Scheduling Queues

❑II. Scheduler

❑III. Context Switching

PREPARED BY GSK
Process Scheduling Contd..

❖I. Scheduling Queues:


❖The operating system maintains several queues for efficient management of
processes.
❖ 1.Job Queue
✓When a new process is created it stays in the job queue and if is ready for
execution it then moves to ready queue.
✓It is maintained in the secondary memory.
✓The long term scheduler (Job scheduler) picks some of the jobs and put them in
the primary memory.

PREPARED BY GSK
Process Scheduling Contd..

❖Ready Queue:
❖From the job queue, the processes which are ready for execution
are shifted to the main memory.
❖In the main memory the processes are kept in the ready queue.
❖In other words, the ready queue contains all those processes that
are waiting for the CPU

PREPARED BY GSK
Process Scheduling Contd..

❖3.Device Queue:
❖Device queue is a queue for which a list of processes waiting
for a particular I/O device.
❖Each device has its own device queue.
❖When a process required some I/O operation, it is then taken
out of the ready queue and kept under the device queue.
❖4.Suspended Queue: It stores the list of suspended process.

PREPARED BY GSK
The OS can use different policies to manage each queue (FIFO, Round Robin,
Priority, etc.). The OS scheduler determines how to move processes between the
ready and run queues which can only have one entry per processor core on the
system; in the above diagram, it has been merged with the CPU.

PREPARED BY GSK
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

PREPARED BY GSK
Long Term Scheduler

❖it is also called job scheduler; it works with the job queue.
❖ Job scheduler selects processes from the job queue and loads
them into the main memory for execution.
❖It executes much less frequently, as there may be long time gap
between the creation of new process in the system.
❖The primary objective of the job scheduler is to control the degree
of multiprogramming.

PREPARED BY GSK
Short Term Scheduler

❖It is also called as CPU scheduler.


❖Its main objective is to increase system performance in accordance
with the chosen set of criteria. It is the change of ready state to
running state of the process. CPU scheduler selects a process among
the processes that are ready to execute and allocates CPU to one of
them.
❖Short-term schedulers are faster than long-term schedulers.

PREPARED BY GSK
Medium Term Scheduler
❖It is also known as Swapper.
❖Sometimes the processes are removed from the memory and from CPU
to reduce the degree of multiprogramming.
❖Then after sometime the processes can be reintroduced into memory
and execution can be continued where it is left off. This scheme is known
as swapping.
❖The Medium Term Scheduler selects a process among the partially
executed or unexecuted swapped out processes and swaps it in the main
memory

PREPARED BY GSK
PREPARED BY GSK
Context Switch

❖Transferring the control of the CPU from one process to other


requires saving the context of currently running process and loading
the context of another ready process. This mechanism of saving and
restoring the context is known as context switch.
❖The portion of the PCB including the process state, memory
management information and CPU scheduling information together
constitutes the Context.
❖The switching periods depends upon the memory speed and the
number of registers used.
PREPARED BY GSK
Context Switch: Example

❖Context switching is the process of asking


your brain to focus on two different things
at the same time—but each has different
meanings, settings, or circumstances.
❖When we switch context, we ask our
brain to change focus while retaining focus.
❖For example, watching football while
trying to bake a cake

PREPARED BY GSK
Cooperating Process in Operating System
Processes are classified into 2 categories.
Independent Process:
❖It is defined as a process that does not share any data and does not
communicate with other process.
❖In other words we can say that modification made to an
independent process does not affect the functioning of other
processes

PREPARED BY GSK
Cooperating Process in Operating System
Cooperating Process:
❖It is defined as a process, which gets affected by any other process.
❖These processes are used for resource sharing and to speed up a
computation procedure.

PREPARED BY GSK
Advantages of process cooperation
Information sharing: Since several users may be interested in the same piece
of information (for instance, a shared file), we must provide an environment
to allow concurrent access to these types of resources.
Computation speedup: If we want a particular task to run faster, we must
break it into subtasks, each of which will be executing in parallel with the
others. Such a speedup can be achieved only if the computer has multiple
processing elements (such as CPUS or I/O channels).
Modularity: We may want to construct the system in a modular fashion,
dividing the system functions into separate processes or threads.

PREPARED BY GSK
Methods of Cooperating Process in OS

❖Cooperating processes in OS requires a communication method


that will allow the processes to exchange data and information.
❖There are two methods by which the cooperating process in OS can
communicate:
❖Cooperation by Sharing
❖Cooperation by Message Passing

PREPARED BY GSK
Cooperation by Sharing

❖The cooperation processes in OS can


communicate with each other using the
shared resource which includes data,
memory, variables, files, etc.
❖Processes can then exchange the
information by reading or writing data to
the shared region.
❖We can use a critical section that
provides data integrity and avoids data
inconsistency.

PREPARED BY GSK
Cooperation by Message Passing

❖The cooperating processes in OS can


communicate with each other with the help
of message passing. The production process
will send the message and the consumer
process will receive the same message.
❖There is no concept of shared memory
instead the producer process will first send
the message to the kernel and then the
kernel sends that message to the consumer
process.

PREPARED BY GSK
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.
❖A thread is also called a lightweight process. Threads provide a way
to improve application performance through parallelism.

PREPARED BY GSK
Difference between Process and Thread
S.N. Process Thread
Thread is light weight, taking lesser resources
1 Process is heavy weight or resource intensive.
than a process.
Process switching needs interaction with operating Thread switching does not need to interact with
2
system. operating system.
In multiple processing environments, each process
All threads can share same set of open files,
3 executes the same code but has its own memory
child processes.
and file resources.
If one process is blocked, then no other process can While one thread is blocked and waiting, a
4
execute until the first process is unblocked. second thread in the same task can run.
Multiple processes without using threads use more Multiple threaded processes use fewer
5
resources. resources.
In multiple processes each process operates One thread can read, write or change another
6
independently of the others. thread's data.

PREPARED BY GSK
Types of Thread in Operating System

1. User Level Threads:


❖User Level Thread is a type of thread
that is not created using system calls.
❖The kernel has no work in the
management of user-level threads.
❖ User-level threads can be easily
implemented by the user

PREPARED BY GSK
Types of Thread in Operating System

2. Kernel Level Threads


❖A kernel Level Thread is a type of thread that can recognize the
Operating system easily.
❖Kernel Level Threads has its own thread table where it keeps track of the
system.
❖The operating System Kernel helps in managing threads.
❖Kernel Threads have somehow longer context switching time.

PREPARED BY GSK
What is Multi-Threading?

❖Multithreading is a technique used in operating systems to improve


the performance and responsiveness of computer systems.
❖ Multithreading allows multiple threads (i.e., lightweight processes)
to share the same resources of a single process, such as the CPU,
memory, and I/O devices.

PREPARED BY GSK
What is Multi-Threading? Contd..

❖The idea is to achieve parallelism by dividing a process into multiple


threads.
❖For example, in a browser, multiple tabs can be different threads.
❖ MS Word uses multiple threads: one thread to format the text,
another thread to process inputs, etc.

PREPARED BY GSK
Unit-1: Important Questions
1. Describe the system components of an operating system and explain them briefly.
2. Discuss the Functionalities of Operating Systems in detail.
3. What is a System call? Discuss major System calls of Operating Systems.
4. Describe the differences among short-term, medium-term, and long-term scheduling
5. Explain about time-sharing operating systems.
6. Define real time system. Explain about real time operating system
7. Discuss about Process Control Block with a neat diagram
8. Distinguish between client-server and peer-to-peer models of distributed systems.
9. Differentiate between Multi Programming, Multi Tasking and Multi processing systems
10.List out the types of operating system and explain batch OS and time sharing OS in brief.
11.Explain about the system calls fork, exit, wait, waitpid and exec
PREPARED BY GSK

You might also like