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

Unit 1(introduction)OPERATING SYSTEMS

The document provides an overview of operating systems, detailing their role as intermediaries between users and hardware, and outlining their primary functionalities such as resource, process, storage, memory, and security management. It categorizes operating systems into types based on purpose and functionality, including batch, multi-programming, multi-processing, multi-user, distributed, network, real-time, and mobile operating systems. Additionally, it discusses the characteristics, goals, and components of operating systems, emphasizing the importance of user convenience, efficient resource utilization, and security.
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)
2 views

Unit 1(introduction)OPERATING SYSTEMS

The document provides an overview of operating systems, detailing their role as intermediaries between users and hardware, and outlining their primary functionalities such as resource, process, storage, memory, and security management. It categorizes operating systems into types based on purpose and functionality, including batch, multi-programming, multi-processing, multi-user, distributed, network, real-time, and mobile operating systems. Additionally, it discusses the characteristics, goals, and components of operating systems, emphasizing the importance of user convenience, efficient resource utilization, and security.
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/ 40

OPERATING SYSTEMS (CST-023)

Unit 1- Introduction:
Introduction to Operating System:
 An operating system acts as an intermediary between the user
of a computer and computer hardware. In short its an interface
between computer hardware and user.
 The purpose of an operating system is to provide an
environment in which a user can execute programs
conveniently and efficiently.
 An operating system is software that manages computer
hardware and software.
 It does assignment of resources like memory, processors and
input / output devices to different processes that need the
resources. The assignment of resources has to be fair and
secure.
Functionalities of Operating System:
1. Resource Management: When multiple processes run on
the system and need different resource like memory, i/o
devices, the OS works as Resource manager , its responsibility is
to provide hardwre to the user. It decreases the load in the
system.
2. Process Management: it include task like scheduling and
Synchronization of process.
3. Storage Management: The file system mechanism used
for the management of the secondary storage like Hard
Disk. NIFS, CIFS, CFS, NFS, etc. All the data is stored in various
tracks of Hard disks that are all managed by the storage
manager.
4. Memory Management: Refers to the management of
primary memory, mainly allocation and de-allocation of
memory to processes. The operating system has to keep track
of how much memory has been used and by which process. It
has to decide which process needs memory space and how
much
5. Security/Privacy Management: Privacy is also provided
by the Operating system using passwords so that unauthorized
applications can’t access programs or data. For example,
Windows uses Kerberos authentication to prevent
unauthorized access to data.
.. .. .. .. .. …

The Operating System as a user Interface:-


1. User (Interacts with the system)
2. System and application programs (Software tools for the user)
3. Operating system (Manages hardware and software resources)
4. Hardware (Physical computing devices)
Goals of Operating System
Primary Goals:
The primary goals of an operating system (OS) are to provide a easy
to use and convenient environment for executing user programs.
1. User Convenience : It should be easy to use, providing a user-
friendly interface and making it simple to interact with the
system.
2. Program Execution: It facilitates the execution of user
programs, providing the necessary environment and services
for them to run.
3. Resource Management: The OS manages and allocates the
computer’s resources, including the CPU, memory, disk storage,
and input/output devices, to ensure fair utilization.
4. Security: The OS protects the system and user data from
unauthorized access, ensuring the confidentiality, integrity, and
availability of information.

Secondary Goals
1. Efficient Resource Utilization: It should aim to maximize the
performance and utilization of computer resources like CPU,
Memory and IO devices, ensuring that the system runs
smoothly and efficiently.
2. Reliability: It should be robust and reliable, able to handle
errors and exceptions gracefully, ensuring that the system
continues to operate smoothly. It should be modular in design
and easy to debug.
Characteristics of Operating Systems
Let us now discuss some of the important characteristic
features of operating systems:
 Device Management: The operating system keeps track of all
the devices. So, it is also called the Input/Output controller that
decides which process gets the device, when and for how much
time.
 File Management: It allocates and de-allocates the resources
and also decides who gets the resource.
 Job Accounting: It keeps track of time and resources used by
various jobs or users.
 Error-detecting Aids: These contain methods that include the
production of dumps, traces, error messages and other
debugging and error-detecting methods.
 Memory Management: It is responsible for managing
the primary memory of a computer, including what part of it
are in use by whom also check how much amount free or used
and allocate process
 Processor Management: It allocates the processor to a process
and then de-allocates the processor when it is no longer
required or the job is done.
 Control on System Performance: It records the delays between
the request for a service and the system.
 Security: It prevents unauthorized access to programs and data
using passwords or some kind of protection technique.
 Convenience: An OS makes a computer more convenient to
use.
 Efficiency: An OS allows the computer system resources to be
used efficiently.
 Ability to Evolve: An OS should be constructed in such a way as
to permit the effective development, testing and introduction
of new system functions at the same time without interfering
with service.
 Throughput: An OS should be constructed so that It can give
maximum throughput (Number of tasks per unit time

Layered Design of Operating System:-

The extended machine provides operations like context save,


dispatching, swapping and I/O initiation. The operating system layer
is located on top of the extended machine layer. This arrangement
considerably simplifies the coding and testing of OS modules by
separating the algorithm of a function from the implementation of its
primitive operations. It is now easier to test, debug and modify an OS
module than in a monolithic OS. We say that the lower layer provides
an abstraction that is the extended machine. We call the operating
system layer the top layer of the OS.

Components of an Operating Systems


There are two basic components of an Operating System.
 Shell
 Kernel
Shell:
Shell is the outermost layer of the Operating System and it handles
the interaction with the user. The main task of the Shell is the
management of interaction between the User and OS. Shell provides
better communication with the user and the Operating System Shell
does it by giving proper input to the user it also interprets input for
the OS and handles the output from the OS. It works as a way of
communication between the User and the OS.

Kernel:
The kernel is one of the components of the Operating System which
works as a core component. The rest of the components depends on
Kernel for the supply of the important services that are provided by
the Operating System. The kernel is the primary interface between
the Operating system and Hardware
The following functions are to be performed by the Kernel.
 It helps in controlling the System Calls.
 It helps in I/O Management.
 It helps in the management of applications, memory, etc

 Difference Between 32-Bit and 64-


Bit Operating Systems

32-Bit Operating System 64-Bit Operating System

32-Bit OS is required for


64-Bit Processors can run on any
running of 32-Bit Processors, as
of the Operating Systems, like
they are not capable of running
32-Bit OS or 64-Bit OS.
on 64-bit processors.

32-Bit OS gives a low efficient 64-Bit Operating System provides


performance. highly efficient Performance.
32-Bit Operating System 64-Bit Operating System

Less amount of data is


A large amount of data can be
managed in 32-Bit Operating
stored in 64-Bit Operating
System as compared to 64-Bit
System.
Os.

32-Bit Operating System can 64-Bit Operating System can


address 2^32 bytes of RAM. address 2^64 bytes of RAM.

Types of Operating Systems


8 Main Operating System Types: Categorized by
Purpose and Functionality
 Batch Operating System
 Multi-Programming Operating System
 Multi-Processing Operating System
 Multi-User Operating Systems
 Distributed Operating System
 Network Operating System
 Real-Time Operating System
 Mobile Operating Systems

1.Batch Operating System:-


This type of operating system does not interact with the computer
directly. There is an operator which takes similar jobs having the
same requirements and groups them into batches. It is the
responsibility of the operator to sort jobs with similar needs. Batch
Operating System is designed to manage and execute a large
number of jobs efficiently by processing them in groups.

Advantages
 Multiple users can share the batch systems.
 The idle time for the batch system is very little.
 It is easy to manage large work repeatedly in batch systems.

Disadvantage:-
 CPU is not used efficiently. When the current process is doing
IO, the CPU is free and could be utilized by other processes
waiting.
 The other jobs will have to wait for an unknown time if any job
fails.
 In a batch operating system, average response time increases as
all processes are processed one by one.

2. Multi-Programming Os:-
Multiprogramming Operating Systems can be simply illustrated as
more than one program is present in the main memory and any
one of them can be kept in execution. This is used for better
utilization of resources.
A multiprogramming operating system allows multiple programs
to reside in memory simultaneously and share CPU time, even on
a single-processor computer.

Key Features and Concepts:


 Memory Management:
The operating system manages the allocation of memory space to
different programs.
 CPU Scheduling:
The operating system determines which program gets to use the
CPU at any given time, often using algorithms like round robin or
priority scheduling.
 I/O Management:
The operating system manages the interaction between programs
and I/O devices.
 Concurrent Execution:
Multiple programs appear to be running simultaneously, although
the CPU is actually switching between them rapidly.
Benefits of Multiprogramming:
 Improved CPU Utilization: The CPU is kept busy by switching
between programs, even if one is waiting for I/O.
 Increased Throughput: More work can be done in a given
period due to concurrent execution.
 Better Resource Sharing: Multiple programs can share
resources, such as the CPU and I/O devices.
Examples:
 Many modern operating systems, such as Windows, macOS,
and Linux, support multiprogramming.

Multi-Tasking /Time-Sharing Os:- (a type of


Multiprogramming system)
every process running in round robin manner. Each task is given
some time to execute so that all the tasks work smoothly. Each
user gets the time of the CPU as they use a single system.

Advantages of Time-Sharing OS
 Each task gets an equal opportunity.
 Fewer chances of duplication of software.
 CPU idle time can be reduced.
 Resource Sharing: Time-sharing systems allow multiple users to
share hardware resources such as the CPU, memory, and
peripherals, reducing the cost of hardware and increasing
efficiency.
 Improved Productivity: Time-sharing allows users to work
concurrently, thereby reducing the waiting time for their turn to
use the computer. This increased productivity translates to
more work getting done in less time.
 Improved User Experience: Time-sharing provides an interactive
environment that allows users to communicate with the
computer in real time, providing a better user experience than
batch processing.
Disadvantages of Time-Sharing OS
 Reliability problem.
 One must take care of the security and integrity of user
programs and data.
 Data communication problem.
 High Overhead: Time-sharing systems have a higher overhead
than other operating systems due to the need for scheduling,
context switching, and other overheads that come with
supporting multiple users.
 Complexity: Time-sharing systems are complex and require
advanced software to manage multiple users simultaneously.
This complexity increases the chance of bugs and errors.
 Security Risks: With multiple users sharing resources, the risk of
security breaches increases. Time-sharing systems require
careful management of user access, authentication, and
authorization to ensure the security of data and software.

Examples:
IBM VM/CMS , TSO(time sharing option), Window terminal
services

3. Multi-Processing Operating System:-


more than one CPU is used for the execution of resources. It betters
the throughput of the System.

Advantages of a Multi-User Operating System


 It increases the throughput of the system as processes can be
parallelized.
 As it has several processors, so, if one processor fails, we can
proceed with another processor

4. Multi-user Operating Systems:


These systems allow multiple users to be active at the same time.
This system can be either a multiprocessor or a single processor
with interleaving.

5. Distributed Operating system:-


These types of operating systems are a recent advancement in the
world of computer technology and are being widely accepted all
over the world and, that too, at a great pace. Various autonomous
interconnected computers communicate with each other using a
shared communication network. Independent systems possess
their own memory unit and CPU. Systems. These systems’
processors differ in size and function. The major benefit of working
with these types of operating systems is that it is always possible
that one user can access the files or software which are not
present on his system but on some other system connected within
this network, i.e., remote access is enabled within the devices
connected to that network.
Advantages of Distributed Operating System
 Failure of one will not affect the other network communication,
as all systems are independent of each other.
 Electronic mail increases the data exchange speed.
 Since resources are being shared, computation is highly fast and
durable.
 Load on host computer reduces.
 These systems are easily scalable as many systems can be easily
added to the network.
 Delay in data processing reduces.
Disadvantages of Distributed Operating System
 Failure of the main network will stop the entire communication.
 To establish distributed systems, the language is not yet well-
defined.
 These types of systems are not readily available as they are very
expensive. Not only that the underlying software is highly
complex and not understood well yet
Examples:- LOCUS

Issues With Distributed Operating Systems


 Networking causes delays in the transfer of data between
nodes of a distributed system. Such delays may lead to an
inconsistent view of data located in different nodes and make it
difficult to know the chronological order in which events
occurred in the system.
 Control functions like scheduling, resource allocation, and
deadlock detection have to be performed in several nodes to
achieve computation speedup and provide reliable operation
when computers or networking components fail.
 Messages exchanged by processes present in different nodes
may travel over public networks and pass through computer
systems that are not controlled by the distributed operating
system. An intruder may exploit this feature to tamper with
messages or create fake messages to fool the authentication
procedure and masquerade as a user of the system

6.Network Operating System:-


These systems run on a server and provide the capability to
manage data, users, groups, security, applications, and other
networking functions. These types of operating systems allow
shared access to files, printers, security, applications, and
other networking functions over a small private network. One
more important aspect of Network Operating Systems is that
all the users are well aware of the underlying configuration,
of all other users within the network, their connections, etc.,
and that’s why these computers are popularly known a tightly
coupled systems
Advantages of Network Operating System
 Highly stable, centralized servers.
 Security concerns are handled through servers.
 New technologies and hardware upgrades are easily
integrated into the system.
 Server access is possible remotely from different
locations and types of systems.
Disadvantages of Network Operating System
 Servers are costly.
 The user has to depend on a central location for most
operations.
 Maintenance and updates are required regularly
7.Real- Time Os:-
These types of OSs serve real-time systems. The time interval
required to process and respond to inputs is very small. This
time interval is called response time. Real-time systems are
used when there are time requirements that are very strict
like missile systems, air traffic control systems, robots, etc.
Types of Real-Time Operating Systems
 Hard Real-Time Systems: Hard Real-Time OSs are meant
for applications where time constraints are very strict,
and even the shortest possible delay is not acceptable.
These systems are built for saving lives like automatic
parachutes or airbags which are required to be readily
available in case of an accident. Virtual memory is rarely
found in these systems.
 Soft Real-Time Systems: These OSs are for applications
where time is less stric

8 Mobile Os:
Mobile operating systems are designed specifically for mobile
devices such as smartphones and tablets. Examples of such
operating systems are Android and iOS. These operating
systems manage the hardware and software resources of the
device, providing a platform for running applications and
ensuring a seamless user experience.
Advantages of Mobile Operating Systems
User-Friendly Interfaces: Mobile operating systems are
designed to be intuitive and easy to use, making them
accessible to a wide range of users.
Extensive App Ecosystems: The availability of a vast number
of applications allows users to customize their devices to
meet their specific needs.
Connectivity Options: Mobile operating systems support
multiple connectivity options, enabling users to stay
connected wherever they go.
Regular Updates: Mobile operating systems receive regular
updates, including new features, security patches, and
performance improvements.
Disadvantages Mobile Operating Systems
Battery Life Constraints: Despite advancements in power
management, battery life remains a challenge for mobile
devices, especially with heavy usage.
Security Risks: Mobile devices are susceptible to various
security threats, such as malware and phishing attacks, which
can compromise user data.
Fragmentation: In the case of Android, the wide range of
devices and customizations can lead to fragmentation,
making it difficult for developers to ensure compatibility
across all devices.
Limited Hardware Resources: Mobile devices have limited
processing power, memory, and storage compared to desktop
computers, which can affect the performance of resource-
intensive applications.

Microkernel in os:-
A MicroKernel is an approach to designing an Operating System (OS).
The microkernel provides very fundamental services required to run
the OS like basic memory management, task scheduling, etc.
Microkernels use Inter-Process Communication (IPC) for
communication

What is kernel:-

A Kernel is the core part of an operating system that manages system


resources. It also acts as a bridge between the application and
hardware of the computer. It is one of the first programs loaded on
start-up (after the Bootloader)

What is a microkernel:-
Microkernel is a type of Operating System that provides some basic
services for an operating system/ These services include memory
management, process scheduling, etc. Some other services like
Device Drivers, File Systems, etc are managed by user-level
processes. User Level Process communicates with Microkernel via
message passing. This way of handling the process makes
microkernels more modular and more flexible than traditional
monolithic kernels.
a microkernel architecture can provide a more secure and flexible
operating system, but it may also come with some performance and
complexity trade-offs. The choice between a microkernel and a
monolithic kernel architecture depends on the specific needs and
requirements of the operating system being developed.
Features of Microkernel-Based Operating System
 Minimal Core : The kernel only manages basic tasks like CPU
scheduling, memory management, and inter-process
communication. All other services (like device drivers) run in
user space, outside the kernel.
 Modularity : System services are separated into independent
modules. This makes it easy to update or replace individual
components without affecting the entire system.
 Stability and Fault Isolation : If a service like a device driver
fails, it won’t crash the whole system. Each service runs
independently, so the core OS remains stable.
 Ease of Maintenance : Since services are independent, fixing
bugs or adding new features doesn’t require major changes to
the kernel itself, making maintenance easier.
Advantages of Microkernel
 Modularity: Because the kernel and servers can be developed
and maintained independently, the microkernel design allows
for greater modularity. This can make adding and removing
features and services from the system easier.
 Performance: Because the kernel only contains the essential
functions required to manage the system, the microkernel
design can improve performance. This can make the system
faster and more efficient.
 Security: The microkernel design can improve security by
reducing the system’s attack surface by limiting the functions
provided by the kernel. Malicious software may find it more
difficult to compromise the system as a result of this.
 Reliability: Microkernels are less complex than monolithic
kernels, which can make them more reliable and less prone to
crashes or other issues.
 Scalability: Microkernels can be easily scaled to support
different hardware architectures, making them more versatile.
 Portability: Microkernels can be ported to different platforms
with minimal effort, which makes them useful for embedded
systems and other specialized applications.
Disadvantages of a Microkernel
 Slower Message Passing: Slower message passing between
user-level processes can affect performance, especially in high-
performance applications.
 More Complex: Increased complexity due to the modular
design can make it more difficult to develop and maintain
the operating system .
 Limited Performance: Limited performance optimization due to
separation of kernel and user-level processes.
 Higher Memory Usage: Higher memory usage compared to a
monolithic kernel.
Conclusion
In conclusion, a microkernel keeps the core of the operating
system small and simple, which makes it more secure and stable.
Since most functions run outside the kernel, it’s easier to fix or
update parts of the system without affecting everything else.
A microkernel focuses on running only the most essential tasks in
the core, such as managing memory and CPU, while leaving other
services like device drivers and file systems to run outside in user
space.

Concept of Virtual Machine.(virtual machines in operating )


A Virtual Machine is an Operating System or application environment
that runs on software that replicates special hardware. The end-user
experience when utilizing a virtual machine is identical to that of
special hardware.
Virtual Machine abstracts the hardware of our personal computer
such as CPU, disk drives, memory, NIC (Network Interface Card), etc,
into many different execution environments as per our
requirements.. For example, VirtualBox.
When we run different processes on an operating system, it creates
an illusion that each process is running on a different processor
having its own virtual memory, with the help of CPU scheduling and
virtual-memory techniques.
There are additional features of a process that cannot be provided by
the hardware alone like system calls and a file system.
The virtual machine approach does not provide these additional
functionalities but it only provides an interface that is the same as
basic hardware. Each process is provided with a virtual copy of the
underlying computer system. We can create a virtual machine for
several reasons, all of which are fundamentally related to the ability
to share the same basic hardware yet also support different
execution environments, i.e., different operating systems
simultaneously. The main drawback of the virtual-machine approach
involves disk systems. Let us suppose that the physical machine has
only three disk drives but wants to support seven virtual machines. It
cannot allocate a disk drive to each virtual machine, because virtual-
machine software itself will need substantial disk space to provide
virtual memory and spooling. The solution is to provide virtual disks.
After which they can run any of the operating systems or software
packages that are available on the underlying machine. The virtual-
machine software is concerned with multi-programming multiple
virtual machines onto a physical machine, but it does not need to
consider any user-support software. This arrangement can provide a
useful way to divide the problem of designing a multi-user interactive
system, into two smaller pieces.
How Does a Virtual Machine Work?
Virtualization is the method of creating a software-based, or “virtual”
version of a computer with good amounts of CPU, memory, and
storage that are “borrowed” from a physical host computer (such as
your personal computer) and/or a remote server. The working of the
virtual machine is very simple just check the published article on
the Working of a Virtual Machine.
Types of Virtual Machine
There are two types of Virtual Machine
 Process Virtual Machine
 System Virtual Machine
Read the published article to know the detail of Types of Virtual
Machine on GFG.
How to Set Up Virtual Machine?
The process for creating a virtual machine varies depending on the
virtualization platform. Many platforms provide wizards and other
capabilities to simplify the process of establishing and deploying a
VM. For ex: To install a Linux Virtual Machine, the user have to follow
the below steps:
Step 1: Make a blank virtual machine.
Step 2: Create a virtual disc for storage.
Step 3: Add a network interface to link the virtual machine to the
network.
Step 4: Install the guest operating system (OS).
Step 5: Register the VM with the content delivery network and attach
any necessary subscriptions.
Step 6: Install any necessary guest agents or drivers.
Advantages of Virtual Machine
 There are no protection problems because each virtual machine
is completely isolated from all other virtual machines.
 Virtual machine can provide an instruction set architecture that
differs from real computers.
 Easy maintenance, availability and convenient recovery.
 Energy and cost savings.
 Easy backup and clone.
 Virtual Machine provide Flexibility and Customization.
Disadvantages of Virtual Machine
 When multiple virtual machines are simultaneously running on
a host computer, one virtual machine can be affected by other
running virtual machines, depending on the workload.
 Virtual machines are not as efficient as a real one when
accessing the hardware.
What is Hypervisors in Virtualization?
Hypervisor as name suggests, it is a software, hardware, or
firmware that generally make virtualization possible. It simply
creates virtualization layers that separates CPU/processors,
RAM and all other physical resources from virtual machines
that we create. Its type includes Native hypervisor and Hosted
hypervisor. It is used to allocate each VM resources such as
CPU, memory, storage, and network to simply run guest OS
and applications. To know more check the published
article Hypervisors on GFG

Processes In OS:-
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.

1 Stack
The process Stack contains the temporary data such as
method/function parameters, return address and local
variables.

Heap
2 This is dynamically allocated memory to a process during its
run time.

Text
3 This includes the current activity represented by the value of
Program Counter and the contents of the processor's registers.

Data
4
This section contains the global and static variables.

Program:
A program is a piece of code which may be a single line or millions of
lines. A computer program is usually written by a computer
programmer in a programming language.
A computer program is a collection of instructions that performs a
specific task when executed by a computer.
A part of a computer program that performs a well-defined task is
known as an algorithm.
A collection of computer programs, libraries and related data are
referred to as a software.

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.
S.N
State & Description
.

Start
1
This is the initial state when a process is first started/created.

Ready
The process is waiting to be assigned to a processor. Ready
processes are waiting to have the processor allocated to them by
2 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.

Running

3 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

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

Terminated or Exit

5 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.
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
as listed below in the table –

S.N
Information & Description
.

Process State
1 The current state of the process i.e., whether it is ready,
running, waiting, or whatever.

Process privileges
2 This is required to allow/disallow access to system
resources.

3 Process ID
Unique identification for each of the process in the
operating system.

Pointer
4
A pointer to parent process.

Program Counter
5 Program Counter is a pointer to the address of the next
instruction to be executed for this process.

CPU registers
6 Various CPU registers where process need to be stored for
execution for running state.

CPU Scheduling Information


7 Process priority and other scheduling information which is
required to schedule the process.

Memory management information

8 This includes the information of page table, memory limits,


Segment table depending on memory used by the
operating system.

Accounting information
9 This includes the amount of CPU used for process
execution, time limits, execution ID etc.

IO status information
10
This includes a list of I/O devices allocated to the process.
Context switching In OS:-
Context switching in an operating system (OS) refers to the process
where the CPU switches from executing one process to another. This
involves saving the current state of the running process (its context)
and loading the state of the new process so it can resume execution
at the point where it was suspended. It's a fundamental mechanism
for enabling multitasking and allowing multiple processes to share
the CPU's resources.

What is Context Switching?


Context switching is the procedure of storing the context or state of a
process so that it can be reloaded when required and execution can
be resumed from the same point as earlier. This is a feature of a
multitasking operating system and allows a single CPU to be shared
by multiple processes.
Context Switching Triggers
There are three major triggers for context switching. These are given
as follows −

1. Multitasking
In a multitasking environment, a process is switched out of the CPU
so another process can be run. The state of the old process is saved,
and the state of the new process is loaded. On a preemptive system,
processes may be switched out by the scheduler.

2. Interrupt Handling
The hardware switches a part of the context when an interrupt
occurs. This happens automatically. Only some of the context is
changed to minimize the time required to handle the interrupt.

3. User and Kernel Mode Switching


A context switch may take place when a transition between the user
mode and kernel mode is required in the operating system.

Context Switching Steps


The steps involved in context switching are as follows −
 Save the context of the process that is currently running on the
CPU. Update the process control block and other important
fields.
 Move the process control block of the above process into the
relevant queue, such as the ready queue, I/O queue, etc.
 Select a new process for execution.
 Update the process control block of the selected process. This
includes updating the process state to running.
 Update the memory management data structures as required.
 Restore the context of the process that was previously running
when it is loaded again on the processor. This is done by loading
the previous values of the process control block and registers.

Thread In OS:
A thread is a single sequence stream within a process. Threads are
also called lightweight processes as they possess some of the
properties of processes. Each thread belongs to exactly one process
 In an operating system that supports multithreading, the
process can consist of many threads. But threads can be
effective only if the CPU is more than 1 otherwise two threads
have to context switch for that single CPU.
 All threads belonging to the same process share – code section,
data section, and OS resources (e.g. open files and signals)
 But each thread has its own (thread control block) – thread ID,
program counter, register set, and a stack
 Any operating system process can execute a thread. we can say
that single process can have multiple threads.

Why do we Need Thread?


 Threads run in concurrent manner that improves the
application performance. Each such thread has its own CPU
state and stack, but they share the address space of the process
and the environment. For example, when we work on Microsoft
Word or Google Docs, we notice that while we are typing,
multiple things happen together (formatting is applied, page is
changed and auto save happens).

 Threads can share common data so they do not need to


use inter-process communication. Like the processes, threads
also have states like ready, executing, blocked, etc.
 Priority can be assigned to the threads just like the process, and
the highest priority thread is scheduled first.
 Each thread has its own Thread Control Block (TCB). Like the
process, a context switch occurs for the thread, and register
contents are saved in (TCB). As threads share the same address
space and resources, synchronization is also required for the
various activities of the thread.
Component of threads:-
 Stack Space: Stores local variables, function calls, and return
addresses specific to the thread.
 Register Set: Hold temporary data and intermediate results for
the thread’s execution.
 Program Counter: Tracks the current instruction being executed
by the thread.

Types Of Threads In Os:-


 User Level Thread
 Kernel Level Thread

1. User Level Thread:-


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. In
case when user-level threads are single-handed processes, kernel-
level thread manages them

Advantages of User-Level Threads


 Implementation of the User-Level Thread is easier than Kernel
Level Thread.
 Context Switch Time is less in User Level Thread.
 User-Level Thread is more efficient than Kernel-Level Thread.
 Because of the presence of only Program Counter, Register Set,
and Stack Space, it has a simple representation

Disadvantages of User-Level Threads


 The operating system is unaware of user-level threads, so
kernel-level optimizations, like load balancing across CPUs, are
not utilized.
 If a user-level thread makes a blocking system call, the entire
process (and all its threads) is blocked, reducing efficiency.
 User-level thread scheduling is managed by the application,
which can become complex and may not be as optimized as
kernel-level scheduling

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. Kernel helps in the management of threads.
Advantages of Kernel-Level Threads
 Kernel-level threads can run on multiple processors or cores
simultaneously, enabling better utilization of multicore systems.
 The kernel is aware of all threads, allowing it to manage and
schedule them effectively across available resources.
 Applications that block frequency are to be handled by the
Kernel-Level Threads.
 The kernel can distribute threads across CPUs, ensuring optimal
load balancing and system performance
Disadvantages of Kernel-Level threads
 Context switching between kernel-level threads is slower
compared to user-level threads because it requires mode
switching between user and kernel space.
 Managing kernel-level threads involves frequent system calls
and kernel interactions, leading to increased CPU overhead.
 A large number of threads may overload the kernel scheduler,
leading to potential performance degradation in systems with
many threads.
 Implementation of this type of thread is a little more complex
than a user-level thread

Difference Between Process and Thread:


The primary difference is that threads within the same process run in
a shared memory space, while processes run in separate memory
spaces. Threads are not independent of one another like processes
are, and as a result, threads share with other threads their code
section, data section, and OS resources (like open files and signals).
But, like a process, a thread has its own program counter (PC),
register set, and stack space.
What is Multi-Threading?
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.
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.

Application itself manages the creation, scheduling, and execution of


threads without relying on the operating system’s kernel. The
application contains a threading library that handles thread creation,
scheduling, and context switching. The operating system is unaware
of User-Level threads and treats the entire process as a single-
threaded entity.
Benefits of Thread in Operating System
 Responsiveness: If the process is divided into multiple threads,
if one thread completes its execution, then its output can be
immediately returned.
 Faster context switch: Context switch time between threads is
lower compared to the process context switch. Process context
switching requires more overhead from the CPU.
 Effective utilization of multiprocessor system: If we have
multiple threads in a single process, then we can schedule
multiple threads on multiple processors. This will make process
execution faster.
 Resource sharing: Resources like code, data, and files can be
shared among all threads within a process. Note: Stacks and
registers can’t be shared among the threads. Each thread has its
own stack and registers.
 Communication: Communication between multiple threads is
easier, as the threads share a common address space. while in
the process we have to follow some specific communication
techniques for communication between the two processes.
 Enhanced throughput of the system: If a process is divided into
multiple threads, and each thread function is considered as one
job, then the number of jobs completed per unit of time is
increased, thus increasing the throughput of the system

You might also like