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

Operating System Concepts

Uploaded by

sameerbisen75
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)
12 views

Operating System Concepts

Uploaded by

sameerbisen75
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/ 19

Operating System Concepts

Operating System Definition: It is a software that works as an interface between a user and
the computer hardware. The primary objective of an operating system is to
make computer system convenient to use and to utilize computer hardware in an efficient
manner. The operating system performs the basic tasks such as receiving input from the
keyboard, processing instructions and sending output to the screen.
The Software is the Non-Touchable Parts of the Computer , and Software’s are those which are
used for Performing an Operation So that Software’s are just used for Making an Application
but hardware’s are those which are used for Performing an Operation .
Operating system is software that is required in order to run application programs and utilities.
It works as a bridge to perform better interaction between application programs and hardware
of the computer. Examples of operating system are UNIX, MS-DOS, MS-Windows –
98/XP/Vista, Windows-

Functions of operating system

Operating System Means that Resource Manager, that manage all the Resources those are
Attached to the System,like Memory,Processor,Input/output Devices.
1) Storage Management: It manage all the Storing and Accessing Files and Directories
Reading/Writing Operations.
Operating system manages overall activities of a computer and the input/output devices
attached to the computer. It is the first software you see when you turn on the computer, and
the last software you see when the computer is turned off. It is the software that enables all
the programs you use. At the simplest level, an operating system does two things:
The first, it manages the hardware and software resources of the computer system. These
resources include the processor, memory, disk space, etc. The second, it provides a stable,
consistent way for applications to deal with the hardware without having-to know all the
details of the hardware.
The first task is very important i.e. managing the hardware and software resources, as various
processes compete to each other for getting the CPU time and memory space to complete the
task. In this regard; the operating system acts as a manager to allocate the available resources
to ‘satisfy the requirements of each process.
The second task i.e. providing a consistent application interface is especially important. A
consistent application program interface (API) allows a user (or S/W developer) to write an
application program on any computer and to run this program on another computer, even if
the hardware configuration is different like as amount of memory, type of CPU or storage
disk. It shields the user of the machine from the low-level details of the machine’s operation
and provides frequently needed facilities.
2) Process Management: It manage all the User and system Process.
3) Memory Management: Operating System also Manages the Computer Memory that is
provided to the process.
4) Extended Machine: It is behaves like an Extended Machine that Provides us Sharing of
Files between Multiple Users.
Mastermind: It performs Many Functions that’s why we can say that Operating System is
a Mastermind.

Different types of operating system

There are different types of operating system those are organized by their Working.
1) Serial Processing: In Serial Processing operating system that use FIFO (First in First Out)
technique for processing the process.
2) Batch Processing: In batch processing a similar type of jobs prepared and processed.
3) Multi-Programming: In Multi programming Operating System Multiple Programs are
Executed on the System at a Time.
4) Real Time System: Real Time System are used there Requires higher and Timely
Response.
5) Distributed Operating System: In this Operating system Data is Stored and Processed
on Multiple Locations.
6) Multiprocessing: In This type of operating system there are two or More CPU in a Single
OS.
7) Parallel operating systems: It manage parallely all running resources of the computer
system.

Services offered by an almost all operating systems:

• User Interface
• Program Execution
• File system manipulation
• Input / Output Operations
• Communication
• Resource Allocation
• Error Detection
• Accounting
• Security and protection

- User Interface

Usually Operating system comes in three forms or types. Depending on the interface their types
have been further subdivided. These are:

• Command line interface


• Batch based interface
• Graphical User Interface

Let's get to know in brief about each of them.


The command line interface (CLI) usually deals with using text commands and a technique for
entering those commands. The batch interface (BI): commands and directives are used to
manage those commands that are entered into files and those files get executed. Another type
is the graphical user interface (GUI): which is a window system with a pointing device (like
mouse or trackball) to point to the I/O, choose from menus driven interface and to make choices
viewing from a number of lists and a keyboard to entry the texts.The operating system must
have the capability to load a program into memory and execute that program. Furthermore, the
program must be able to end its execution, either normally or abnormally / forcefully.

-File System Manipulation in Operating System

Programs need has to be read and then write them as files and directories. File handling portion
of operating system also allows users to create and delete files by specific name along with
extension, search for a given file and / or list file information. Some programs comprise of
permissions management for allowing or denying access to files or directories based on file
ownership.

-I/O operations in Operating System

A program which is currently executing may require I/O, which may involve file or other I/O
device. For efficiency and protection, users cannot directly govern the I/O devices. So, the OS
provide a means to do I/O Input / Output operation which means read or write operation with
any file.

-Communication System of Operating System

Process needs to swap over information with other process. Processes executing on same
computer system or on different computer systems can communicate using operating system
support. Communication between two processes can be done using shared memory or via
message passing.

-Resource Allocation of Operating System

When multiple jobs running concurrently, resources must need to be allocated to each of them.
Resources can be CPU cycles, main memory storage, file storage and I/O devices. CPU
scheduling routines are used here to establish how best the CPU can be used.

-Error Detection

Errors may occur within CPU, memory hardware, I/O devices and in the user program. For
each type of error, the OS takes adequate action for ensuring correct and consistent computing.

-Accounting

This service of the operating system keeps track of which users are using how much and what
kinds of computer resources have been used for accounting or simply to accumulate usage
statistics.
-Protection and Security

Protection includes in ensuring all access to system resources in a controlled manner. For
making a system secure, the user needs to authenticate him or her to the system before using
(usually via login ID and password).

-User Operating system interface


The user and operating system are connected with each other with the help of interface, so
interface is used to connect the user and OS.
In computers there are different types of interface that can be used for connection with
computers to users and their connection is responsible for data transfer.
Also, in computers there are different interfaces. These interfaces are not necessarily used but
can be used in computers whenever it is needed. So, different types of tasks can be performed
by the help of different interfaces.
◼ Command line interface
The command-line interface is an interface whenever the user needs to have different
commands regarding the input and output and then a task is performed so this is called the
command-line argument and it is used to execute the output and create, delete, print, copy,
paste, etc.
All these operations are performed with the help of the command-line interface.
The interface is always connected to the OS so that the command given by the user directly
works by the OS and a number of operations can be performed with the help of the command
line interface because multiple commands can be interrupted at same time and execute only
one.
The command line interface is necessary because all the basic operations in the computer are
performed with the help of the OS and it is responsible for memory management. By using
this we can divide the memory and we can use the memory.
- Command Line Interface advantages −
• Controls OS or application
• faster management
• ability to store scripts which helps in automating regular tasks.
• Troubleshoot network connection issues.

- Command Line Interface disadvantages −


• The steeper learning curve is associated with memorizing commands and a
complex syntax.
• Different commands are used in different shells.
Graphical user interface
The graphical user interface is used for playing games, watching videos, etc. these are done
with the help of GUI because all these applications require graphics.
The GUI is one of the necessary interfaces because only by using the user can clearly see the
picture, play videos.
So we need GUI for computers and this can be done only with the help of an operating system.
When a task is performed in the computer then the OS checks the task and defines the interface
which is necessary for the task. So, we need GUI in the OS.
The basic components of GUIs are −
• Start menu with program groups
• Taskbar which showing running programs
• Desktop screen
• Different icons and shortcuts.
Choice of interface
The interface that is used with the help of OS for a particular task and that task can be
performed with minimum possible time and the output is shown on the screen in that case we
use the choice of interface.
The choice of interface means the OS checks the task and finds out which interface can be
suitable for a particular task. So that type of interface is called the choice of interface and this
can be done with the help of an OS.

System call
A system call is a function that a user program uses to ask the operating system for a particular
service. User programmers can communicate with the operating system to request its services
using the interface that is created by a system call.System calls serve as the interface between
an operating system and a process. System calls can typically be found as assembly language
instructions. They are also covered in the manuals that the programmers working at the
assembly level use. When a process in user mode needs access to a resource, system calls are
typically generated. The resource is then requested from the kernel via a system call.

A system calls in computing is the programmatic method by which a computer programme


asks the kernel of the operating system it is running on for a service. Programs can interact
with the operating system by making a system call. When a computer programme requests
something from the kernel of the operating system, it performs a system call.

System call uses Application Programming Interfaces to provide operating system services to
user programmes (API). It offers a point of contact between processes and the operating system
so that user-level processes can ask for the operating system's assistance. The only ways to
access the kernel system are through system calls. System calls are required for all programmes
that require resources.

The following is a diagram that illustrates what is system call in an operating system and how
the system call is executed:

This diagram shows how the processes normally run in user mode until a system call interrupts
them. The system call is then carried out in kernel mode according to priority. The control
switches back to user mode after the system call has been completed, allowing user processes
to continue running.

Following are the examples of system calls:

The most common system calls used on Unix system calls, Unix-like, and other POSIX-
compliant operating systems are open, read, write, close, wait, exec, fork, exit, and kill. There
are hundreds of systems calls in many contemporary operating systems. For instance, Linux
and OpenBSD each have over 300 different calls, NetBSD and FreeBSD both have over 500,
and Windows has close to 2000 system calls, split between win32k and ntdll.

Tools like strace, ftrace, and truss allow a process to run from the beginning and report every
system call it makes. They can also attach to an already running process and intercept any
system call made by that process if the action does not conflict with the user's permissions.

If we need to copy data from one file into another, we can do so by writing programme code.
The names of the two files, the input and output files, are the first piece of data that the
programme needs. This kind of programme execution requires some system calls from the
OS in an interactive system.

• Writing a prompting message on the screen comes first.


• Second, read the characters that define the two files from the keyboard.
How Does the System Call work?

The Applications operate in user space, a portion of memory. The operating system's kernel,
which runs in kernel space, is reached through a system call. An application must first
request permission from the kernel before it can create a system call. It accomplishes this
by sending an interrupt request, which pauses the running process and gives the kernel
control.

The kernel carries out the requested action, such as creating or deleting a file, if the request
is approved. The output of the kernel is provided to the application as input. Once the input
is received, the application continues the process. The kernel transfers data from kernel
space to user space in memory after the operation is complete and returns the results to the
application.

A straightforward system call, like getting the system date and time, might only return a
result in a few nanoseconds. It might take a few seconds to complete a more complex system
call, like connecting to a network device. To prevent bottlenecks, most operating systems
start a separate kernel thread for each system call. Because modern operating systems are
multi-threaded, they can manage multiple system

Types of System Calls in OS

There are primarily 5 different types of system calls in the operating system:

1. Process Control

The following services are provided by Process Control System calls that are used to control
a process.

• To forcefully abort the process, simply end it normally.


• Execute a process after loading it into the main memory.
• Terminate the current process before starting a new one.
• Wait for a process to complete running. Wait until a specific event happens, then
announce it once it has.
• Allocate memory to a process, then release the memory if the process is terminated.
2. File Management

The following services are provided by system call for file management:

• Making and erasing files


• Open the file, then close it.
• Write to a specific file, read from a specific file.
• To obtain a file's attribute and to change a file's attribute
3. Device Management

The following services are offered by a system call that controls I/O devices:

• Devices might be needed while a process is running. such as access to the file system,
I/O devices, main memory, etc.
• As a result, it can ask for a device and then release it once the task is complete.
• when a requested device is granted access by the process. It is capable of reading,
writing, and repositioning operations.
• In order to obtain or modify a specific device's attribute.
• To detach a device from the processor that is currently executing a command, the call
can be made.

4. Information Maintenance

The system calls for information maintenance call moves data from the user programme to
the operating system. Considering this, the services offered by this type of system call are:

• Obtain the system's time or date. Set the system's time or date.
• Obtain system-related information. Configure the system data.
• Obtain the characteristics of a specific operating system process. Alternatively, of a
specific file on the system or on any attached devices.
• Set the characteristics of a specific operating system process. Alternatively, of a specific
file on the system or on any attached devices.

5. Communication

Such a system call facilitates the system's network connection. The services that these
system calls offer are:

• Open a fresh connection to send the data. After the transmission is finished, disconnect
from the connection.
• On a particular connection, send a message. Obtain communication from a specific
connection.
• Identify and connect a specific remote device to the network. Remove a specific remote
computer or device from the network.
• Example of System Calls in Windows and Unix

Types of System Calls Windows Linux

Process CreateProcess() fork()


Control ExitProcess() exit()
WaitForSingleObject() wait()

File Management CreateFile() open()


ReadFile() read()
WriteFile() write()
CloseHandle() close()

Device Management SetConsoleMode() ioctl()


ReadConsole() read()
WriteConsole() write()

Information GetCurrentProcessID() getpid()


Maintenance SetTimer() alarm()
Sleep() sleep()

Communication CreatePipe() pipe()


CreateFileMapping() shmget()
MapViewOfFile() mmap()

Rules for Passing Parameters to the System Call

Following are the rules for passing parameters to the system call:

• The system call cannot accept the floating-point parameters as a parameter.


• In the system call, a finite number of arguments may be passed.
• If there are additional arguments, they should be stored in the memory block, and the
register contains the address of that memory block.
• Only the operating system has the ability to push parameters and pop them from the
stack.

Why Do You Need System Calls in Operating System?

The following circumstances involve the use of system calls in OS:

• System calls are necessary for reading and writing from files.
• System calls are necessary for a file system to add or remove files.
• New processes are created and managed using system calls.
• System calls are required for packet sending and receiving over network connections.
• A system call is required to access hardware devices like scanners and printers.

What is the Purpose of System Calls in OS?

The purpose of system calls serves as the interface between an operating system and a
process. System calls can typically be found as assembly language instructions. They are
also covered in the manuals that the programmers working at the assembly level use. When
a process in user mode needs access to a resource, system calls are typically generated. The
resource is then requested from the kernel via a system call.

System calls are required in in following circumstances:

• If a file system needs files to be created or deleted. A system call is also necessary for
reading and writing from files.
• development and administration of new procedures.
• System calls are also required for network connections. This also applies to packet
sending and receiving.
• A system call is necessary to access hardware such as a printer, scanner, etc.
Looking to master Python programming? Discover the best Python programming
course that guarantees to take your skills to the next level. Start coding like a pro today!

Conclusion

The interface by which the process interacts with the system call is called a system call.
There are two operating modes for computers:
• kernel mode
• user mode
When a system call is made, the process transitions from user mode to kernel mode. Once
the system call has finished running, the control is returned to the user mode

Monolithic Structure of Operating System

The monolithic operating system is a very basic operating system in which file management,
memory management, device management, and process management are directly controlled
within the kernel. The kernel can access all the resources present in the system. In monolithic
systems, each component of the operating system is contained within the kernel. Operating
systems that use monolithic architecture were first time used in the 1970s.

The monolithic operating system is also known as the monolithic kernel. This is an old
operating system used to perform small tasks like batch processing and time-sharing tasks in
banks. The monolithic kernel acts as a virtual machine that controls all hardware parts.

It is different from a microkernel, which has limited tasks. A microkernel is divided into two
parts, kernel space, and user space. Both parts communicate with each other through IPC
(Inter-process communication). Microkernel's advantage is that if one server fails, then the
other server takes control of it.

Monolithic kernel

A monolithic kernel is an operating system architecture where the entire operating system is
working in kernel space. The monolithic model differs from other operating system
architectures, such as the microkernel architecture, in that it alone defines a high-level virtual
interface over computer hardware.

A set of primitives or system calls implement all operating system services such as process
management, concurrency, and memory management. Device drivers can be added to the
kernel as modules.

Advantages of Monolithic Kernel

Here are the following advantages of a monolithic kernel, such as:

o The execution of the monolithic kernel is quite fast as the services such as memory
management, file management, process scheduling, etc., are implemented under the
same address space.
o A process runs completely in single address space in the monolithic kernel.
o The monolithic kernel is a static single binary file.

Disadvantages of Monolithic Kernel


Here are some disadvantages of the monolithic kernel, such as:

o If any service fails in the monolithic kernel, it leads to the failure of the entire system.
o The entire operating system needs to be modified by the user to add any new service.

Monolithic System Architecture

A monolithic design of the operating system architecture makes no special accommodation for
the special nature of the operating system. Although the design follows the separation of
concerns, no attempt is made to restrict the privileges granted to the individual parts of the
operating system. The entire operating system executes with maximum privileges. The
communication overhead inside the monolithic operating system is the same as that of any
other software, considered relatively low.

CP/M and DOS are simple examples of monolithic operating systems. Both CP/M and DOS
are operating systems that share a single address space with the applications.

o In CP/M, the 16-bit address space starts with system variables and the application area.
It ends with three parts of the operating system, namely CCP (Console Command
Processor), BDOS (Basic Disk Operating System), and BIOS (Basic Input/Output
System).
o In DOS, the 20-bit address space starts with the array of interrupt vectors and the system
variables, followed by the resident part of DOS and the application area and ending
with a memory block used by the video card and BIOS.

Advantages of Monolithic Architecture:


Monolithic architecture has the following advantages, such as:

o Simple and easy to implement structure.


o Faster execution due to direct access to all the services

Disadvantages of Monolithic Architecture:

Here are some disadvantages of monolithic architecture:

o The addition of new features or removal of obsolete features is very difficult.


o Security issues are always there because there is no isolation among various servers
present in the kernel.

Modular Monolithic Systems

Modular operating systems and most modern monolithic operating systems such as OS-9
OpenVMS, Linux, BSD, SunOS, AIX, and MULTICS can dynamically load (and unload)
executable modules at runtime.

This modularity of the operating system is at the binary level and not at the architecture level.
Modular monolithic operating systems are not confused with the architectural level of
modularity inherent in server-client operating systems (and its derivatives sometimes marketed
as the hybrid kernel) that use microkernels and servers.

Practically, dynamically loading modules is simply a more flexible way of handling the
operating system image at runtime instead of rebooting with a different operating system
image. The modules allow easy extension of the operating systems' capabilities as required.
Dynamically loadable modules incur a small overhead when compared to building the module
into the operating system image.

However, in some cases, loading modules dynamically helps keep the amount of code running
in kernel space to a minimum. For example, to minimize operating system footprint for
embedded devices or those with limited hardware resources. Namely, an unloaded module need
not be stored in scarce random access memory.

Limitations of Monolithic System

The monolithic operating system has the following limitations, such as:

o Code written in this operating system (OS) is difficult to port.


o Monolithic OS has more tendencies to generate errors and bugs. The reason is that user
processes use the same address locations as the kernel.
o Adding and removing features from monolithic OS is very difficult. All the code needs
to be rewritten and recompiled to add or remove any feature.
Features of Monolithic System

The monolithic operating system provides the following features to the users, such as:

1. Simple structure: This type of operating system has a simple structure. All the
components needed for processing are embedded into the kernel.
2. Works for smaller tasks: It works better for performing smaller tasks as it can handle
limited resources.
3. Communication between components: All the components can directly communicate
with each other and also with the kernel.
4. Fast operating system: The code to make a monolithic kernel is very fast and robust.

Difference between Monolithic Kernel and Microkernel

A kernel is the core part of an operating system, and it manages the system resources. A kernel
is like a bridge between the application and hardware of the computer. The kernel can be
classified further into two categories, Microkernel and Monolithic Kernel.

The microkernel is a type of kernel that allows customization of the operating system. It runs
on privileged mode and provides low-level address space management and Inter-Process
Communication (IPC). Moreover, OS services such as file system, virtual memory manager,
and CPU scheduler are on top of the microkernel. Each service has its own address space to
make them secure. Besides, the applications also have their own address spaces. Therefore,
there is protection among applications, OS Services, and kernels.

A monolithic kernel is another classification of the kernel. In monolithic kernel-based systems,


each application has its own address space. Like microkernel, this one also manages system
resources between application and hardware, but user services and kernel services are
implemented under the same address space. It increases the size of the kernel, thus increases
the size of the operating system as well.This kernel provides CPU scheduling, memory
management, file management, and other system functions through system calls. As both
services are implemented under the same address space, this makes operating system execution
faster. Below are some more differences between Microkernel and Monolithic kernel, such as:

Process Table and Process Control Block (PCB)


••• creating a process, the operating system performs several operations. To identify the
While
processes, it assigns a process identification number (PID) to each process. As the operating
system supports multi-programming, it needs to keep track of all the processes. For this task,
the process control block (PCB) is used to track the process’s execution status. Each block of
memory contains information about the process state, program counter, stack pointer, status of
opened files, scheduling algorithms, etc.
All this information is required and must be saved when the process is switched from one
state to another. When the process makes a transition from one state to another, the operating
system must update information in the process’s PCB. A process control block (PCB)
contains information about the process, i.e. registers, quantum, priority, etc. The process table
is an array of PCBs, that means logically contains a PCB for all of the current processes in
the system.

1. Pointer: It is a stack pointer that is required to be saved when the process is


switched from one state to another to retain the current position of the process.
2. Process state: It stores the respective state of the process.
3. Process number: Every process is assigned a unique id known as process ID or
PID which stores the process identifier.
4. Program counter: It stores the counter,: which contains the address of the next
instruction that is to be executed for the process.
5. Register: These are the CPU registers which include the accumulator, base,
registers, and general-purpose registers.
6. Memory limits: This field contains the information about memory management
system used by the operating system. This may include page tables, segment
tables, etc.
7. Open files list : This information includes the list of files opened for a process.
Additional Points to Consider for Process Control Block (PCB)
• Interrupt handling: The PCB also contains information about the interrupts that
a process may have generated and how they were handled by the operating
system.
• Context switching: The process of switching from one process to another is
called context switching. The PCB plays a crucial role in context switching by
saving the state of the current process and restoring the state of the next process.
• Real-time systems: Real-time operating systems may require additional
information in the PCB, such as deadlines and priorities, to ensure that time-
critical processes are executed in a timely manner.
• Virtual memory management: The PCB may contain information about a
process’s virtual memory management, such as page tables and page fault
handling.
• Inter-process communication: The PCB can be used to facilitate inter-process
communication by storing information about shared resources and communication
channels between processes.
• Fault tolerance: Some operating systems may use multiple copies of the PCB to
provide fault tolerance in case of hardware failures or software errors.
Advantages-
1. Efficient process management: The process table and PCB provide an efficient
way to manage processes in an operating system. The process table contains all
the information about each process, while the PCB contains the current state of the
process, such as the program counter and CPU registers.
2. Resource management: The process table and PCB allow the operating system
to manage system resources, such as memory and CPU time, efficiently. By
keeping track of each process’s resource usage, the operating system can ensure
that all processes have access to the resources they need.
3. Process synchronization: The process table and PCB can be used to synchronize
processes in an operating system. The PCB contains information about each
process’s synchronization state, such as its waiting status and the resources it is
waiting for.
4. Process scheduling: The process table and PCB can be used to schedule
processes for execution. By keeping track of each process’s state and resource
usage, the operating system can determine which processes should be executed
next.
Disadvantages-
1. Overhead: The process table and PCB can introduce overhead and reduce system
performance. The operating system must maintain the process table and PCB for
each process, which can consume system resources.
2. Complexity: The process table and PCB can increase system complexity and
make it more challenging to develop and maintain operating systems. The need to
manage and synchronize multiple processes can make it more difficult to design
and implement system features and ensure system stability.
3. Scalability: The process table and PCB may not scale well for large-scale systems
with many processes. As the number of processes increases, the process table and
PCB can become larger and more difficult to manage efficiently.
4. Security: The process table and PCB can introduce security risks if they are not
implemented correctly. Malicious programs can potentially access or modify the
process table and PCB to gain unauthorized access to system resources or cause
system instability.
5. Miscellaneous accounting and status data – This field includes information
about the amount of CPU used, time constraints, jobs or process number, etc. The
process control block stores the register content also known as execution content
of the processor when it was blocked from running. This execution content
architecture enables the operating system to restore a process’s execution context
when the process returns to the running state. When the process makes a transition
from one state to another, the operating system updates its information in the
process’s PCB. The operating system maintains pointers to each process’s PCB in
a process table so that it can access the PCB
quickly.

Process Table and Process Control Block – FAQ’s


1: What is a Process Control Block (PCB)?
A process control block (PCB) is a data structure used by operating systems to store
important information about running processes. It contains information such as the unique
identifier of the process (Process ID or PID), current status, program counter, CPU
registers, memory allocation, open file descriptions and accounting information. The circuit
is critical to context switching because it allows the operating system to efficiently manage
and control multiple processes.

Context Switch in Operating System


•••
An operating system is a program loaded into a system or computer. and manage all the other
program which is running on that OS Program, it manages the all other application programs.
or in other words, we can say that the OS is an interface between the user and computer
hardware.
So in this article, we will learn about what is Context switching in an Operating System and
see how it works also understands the triggers of context switching and an overview of the
Operating System.
Context Switch
Context switching in an operating system involves saving the context or state of a running
process so that it can be restored later, and then loading the context or state of another. process
and run it.
Context Switching refers to the process/method used by the system to change the process from
one state to another using the CPUs present in the system to perform its job.
Example – Suppose in the OS there (N) numbers of processes are stored in a Process Control
Block(PCB). like The process is running using the CPU to do its job. While a process is
running, other processes with the highest priority queue up to use the CPU to complete their
job.
The Need for Context Switching
Context switching enables all processes to share a single CPU to finish their execution and
store the status of the system’s tasks. The execution of the process begins at the same place
where there is a conflict when the process is reloaded into the system.
The operating system’s need for context switching is explained by the reasons listed below.
1. One process does not directly switch to another within the system. Context
switching makes it easier for the operating system to use the CPU’s resources to
carry out its tasks and store its context while switching between multiple
processes.
2. Context switching enables all processes to share a single CPU to finish their
execution and store the status of the system’s tasks. The execution of the process
begins at the same place where there is a conflict when the process is reloaded
into the system.
3. Context switching only allows a single CPU to handle multiple processes requests
parallelly without the need for any additional processors.
Context Changes as a Trigger
The three different categories of context-switching triggers are as follows.
1. Interrupts
2. Multitasking
3. User/Kernel switch
Interrupts: When a CPU requests that data be read from a disc, if any interruptions occur,
context switching automatically switches to a component of the hardware that can handle the
interruptions more quickly.
Multitasking: The ability for a process to be switched from the CPU so that another process
can run is known as context switching. When a process is switched, the previous state is
retained so that the process can continue running at the same spot in the system.
Kernel/User Switch: This trigger is used when the OS needed to switch between the user
mode and kernel mode.
When switching between user mode and kernel/user mode is necessary, operating systems
use the kernel/user switch.
Process Control Block
So, The Process Control block(PCB) is also known as a Task Control Block. it represents a
process in the Operating System. A process control block (PCB) is a data structure used by a
computer to store all information about a process. It is also called the descriptive process. When
a process is created (started or installed), the operating system creates a process manager.
State Diagram of Context Switching
Working Process Context Switching
So the context switching of two processes, the priority-based process occurs in the ready queue
of the process control block. These are the following steps.
• The state of the current process must be saved for rescheduling.
• The process state contains records, credentials, and operating system-specific
information stored on the PCB or switch.
• The PCB can be stored in a single layer in kernel memory or in a custom OS file.
• A handle has been added to the PCB to have the system ready to run.
• The operating system aborts the execution of the current process and selects a
process from the waiting list by tuning its PCB.
• Load the PCB’s program counter and continue execution in the selected process.
• Process/thread values can affect which processes are selected from the queue, this
can be important.

You might also like