Os Module 1
Os Module 1
MODULE- 1 :- Introduction: operating system, history (1990s to 2000 and beyond), distributed
computing, parallel computation. Process concepts: definition of process, process states-Life cycle of
a process, process management- process state transitions, process control block(PCB), process
operations , suspend and resume, context switching, Interrupts -Interrupt processing, interrupt classes,
Inter process communication-signals, message passing.
An Operating System (OS) is fundamental software that manages computer hardware and
software resources and provides a wide range of services for computer programs. The OS
serves as an intermediary between the user and the computer hardware. It manages tasks such
as executing programs, managing files, controlling hardware devices, and handling security,
among others.
A computer system can be divided into four components as shown in Figure They are:
•Hardware : Consists of central processing unit (CPU), memory and I/O devices and provides
the basic computing resources
•Operating system: Controls and coordinates the use of hardware among various
application software for different users.
•Application programs: defines the ways in which the computing resources are used to
solve the problems of users. For example, word processors, spreadsheets,
compilers, browsers etc.
• User View
• System View
The user's view of the computer varies according to the interface being used. The design
on OS varies depending on type of the user or work to be carried out as explained below:
•User of PC: OS for personal computers is aimed at maximizing the work that the user is
performing. Hence, the OS design is mostly for the ease of use rather than the performance.
And, resource utilization is not taken into consideration.
•User of Handheld Computers: Handheld devices like mobiles, tablets are common
nowadays. Because of power, speed and interface limitations, they may perform
relatively less operations. So, their OS are designed for individual usability by
keeping battery life in mind.
Some computers have little or no user view. For example, embedded computers in home
devices and automobiles may have numeric keypads and may turn indicator lights on or off
to show status, but they and their operating systems are designed primarily to run without
user intervention.
From the computer's point of view, the OS is the program closely involved with the
hardware. In this context, we can view an OS as a resource allocator. A computer system
has many resources that may be required to solve a problem: CPU time, memory
space, file-storage space, I/O devices, and so on. The OS acts as the manager of these
resources by allocating the resources to the programs and users efficiently.
Another view of OS focuses on controlling various I/O devices and user programs. As a
control program, OS manages the execution of user programs to prevent errors and
improper use of computer.
The aim of any computer system is to execute user programs to solve user’s problems. As
computer hardware alone is not easy to use, application programs/softwares have been
created for solving the problems. Such programs require certain common operations like
controlling I/O devices etc. The common functions of controlling and allocating
resources are brought together into one piece of software known as Operating System.
The widely accepted definition of OS goes like this: OS is the program running all times on
the computer (also called as kernel), with all other programs being treated as application
programs.
It is easier to define an operating system by what it does than by what it is. The primary
goal of some operating system is convenience for the user. Operating systems exist
because they are supposed to make it easier to compute with them than without them. This
view is particularly clear when you look at operating systems for small PCs.
The primary goal of other operating systems is efficient operation of the computer system.
This is the case for large, shared, multi-user systems. These systems are expensive, so it is
desirable to make them as efficient as possible.
These two goals - convenience and efficiency-are sometimes contradictory. In the past,
efficiency was often more important than convenience. Thus, much of operating-system
theory concentrates on optimal use of computing resources. Operating systems have also
evolved over time. For example, UNIX started with a keyboard and printer as its interface,
limiting how convenient it could be for the user. Over time, hardware changed, and
UNIX was ported to new hardware with more user-friendly interfaces. Many graphic
user interfaces (GUIs) were added, allowing UNIX to be more convenient for users while
still concentrating on efficiency.
The designers of OS face many tradeoffs related to efficiency and convenience. Lot of
continuous revision and updation is necessary. Still, the success of OS depends on its
users. In past 50 years, OS evolved into different phases. And, OS and computer
architecture have influenced each other. To facilitate the use of the hardware, researchers
developed operating systems. Users of the operating systems then proposed changes in
hardware design to simplify them.
1. Resource Management: The OS manages the computer's resources, such as the CPU,
memory, input/output devices, and storage devices, ensuring their efficient use. This
includes tasks like scheduling tasks for the CPU, managing memory allocation, and
organizing file storage. The OS is responsible for efficiently managing the system's
resources, including the CPU, memory, storage, and input/output devices. It ensures that
each resource is allocated appropriately, avoiding conflicts and inefficiencies. For
example, the OS decides which process gets to use the CPU and for how long, using
scheduling algorithms. Similarly, it manages memory allocation, deciding which parts of
memory should be assigned to running processes. By managing these resources, the OS
ensures smooth multitasking and optimal performance. It also manages power usage in
modern systems to prevent unnecessary consumption. Overall, the OS strives to balance
resource use across all running processes, maximizing efficiency.
4. File System Management: The OS provides a file system to manage data storage and
access. It handles operations such as creating, reading, writing, and deleting files, and it
organizes files into directories or folders for easier access. The OS manages the
organization, storage, retrieval, naming, and protection of files. It provides an interface
for users and applications to interact with files, allowing them to create, read, write, and
delete files. The file system organizes data into directories or folders for easier
management and access. It also manages file permissions, ensuring that users can only
access files they are authorized to use. The OS ensures that files are stored efficiently on
storage devices and implements mechanisms for data recovery in case of system crashes.
5. Input/Output (I/O) Management: The OS controls and manages the input and output
devices (such as the keyboard, mouse, printer, and disk drives) and ensures that data is
transferred efficiently between the hardware and software. The OS is responsible for
managing input and output operations, ensuring that data is transferred between hardware
devices and software programs. It provides an abstraction layer for devices, allowing
software to interact with hardware without needing to understand the specific device
details. The OS uses device drivers to communicate with different hardware devices like
keyboards, printers, and hard drives. It schedules I/O operations to prevent bottlenecks
and ensures that data is transferred efficiently. The OS also handles I/O buffering, where
data is temporarily stored in memory while waiting to be processed. Proper I/O
management improves system responsiveness and prevents data loss during transfers.
6. Security and Protection: The OS ensures the protection of data and resources from
unauthorized access. It uses techniques such as authentication (passwords) and access
control lists (ACLs) to limit access to files and processes. It also ensures that one process
does not disrupt or interfere with others. Security and protection mechanisms in the OS
ensure that system resources are safeguarded against unauthorized access. The OS uses
authentication methods, like usernames and passwords, to verify the identity of users
before granting access. It also implements access control policies, specifying which users
or processes can access specific files or resources. The OS employs encryption to protect
sensitive data both in storage and during transmission. Additionally, it isolates processes
from one another, preventing them from interfering with each other's memory and data.
The OS monitors for suspicious activity, such as malware or unauthorized access
attempts, and takes corrective actions when necessary. These security features are crucial
for maintaining a secure computing environment.
7. User Interface: The OS provides a user interface (UI) to allow users to interact with the
system. This could be a command-line interface (CLI) or a graphical user interface (GUI),
where users can input commands or use graphical tools. The user interface (UI) is the
means through which users interact with the operating system. There are two main types:
command-line interfaces (CLI) and graphical user interfaces (GUI). In a CLI, users type
text-based commands to interact with the system, while in a GUI, users interact with
visual elements like windows, icons, and buttons. The OS provides the necessary tools for
users to perform tasks like file management, running applications, and configuring system
settings. A well-designed UI enhances the user experience by making it intuitive and easy
to use. It also supports accessibility features for users with disabilities. The OS ensures
that the UI is responsive and meets the needs of a diverse user base.
Operating systems come in various forms, each suited to different use cases. Batch OS
handles tasks without user interaction and processes them in batches, often used in early
computing systems. Time-sharing OS allows multiple users or tasks to share the system by
rapidly switching between them, offering the appearance of simultaneous execution. Real-
time OS is designed to handle tasks that require precise timing, like those in embedded
systems. Distributed OS connects multiple computers to work together as a single system,
sharing resources across a network. Network OS allows devices to connect and share
resources over a network. The choice of OS depends on the specific requirements of the
system and its users.
1. Batch Operating System: Early operating systems that were designed to handle a series
of tasks or jobs in a batch. No direct user interaction was involved. Examples include
systems from the 1950s and 1960s. A Batch Operating System is an early type of
operating system designed to handle tasks in groups or "batches" without user interaction
during execution. In this system, jobs (programs or tasks) are collected into a batch and
executed sequentially. The jobs do not need user input while running; instead, they are
processed in the background in a continuous stream. This was common in the 1950s and
1960s when users submitted jobs to be processed on large mainframes. After one job
completes, the next job in the batch starts automatically, and users would typically not be
aware of when their job was running. One example is the IBM 704, which handled tasks
in a batch system. This model made it easier to process tasks more efficiently than the
earlier method of requiring user input for each task.
3. Real-time Operating Systems (RTOS): These are designed to handle real-time tasks
where processing must be done within certain time constraints. Examples include
embedded systems, like those in medical devices or automotive control systems. A Real-
time Operating System (RTOS) is an OS designed to process tasks or data with strict
timing constraints. In an RTOS, the system must guarantee that specific tasks are
completed within a defined time period, often referred to as deadlines. This is crucial in
environments like medical devices, automotive control systems, or industrial automation,
where failure to meet timing requirements can lead to catastrophic outcomes. RTOS is
designed to handle high-priority tasks with low latency and precise timing control.
Examples of RTOS include VxWorks, FreeRTOS, and QNX. These systems prioritize
tasks to ensure that critical operations are completed on time.
4. Distributed Operating System: In this system, multiple computers work together and
share resources to perform tasks, presenting themselves to the user as a single system.
Examples include cloud computing systems and certain types of networked systems. A
Distributed Operating System manages a group of separate computers, presenting them as
a unified system to the user. These systems coordinate multiple computers or nodes over
a network to share resources such as processing power, memory, and storage. The goal is
to allow for improved performance, scalability, and fault tolerance by utilizing multiple
machines. The user perceives the system as a single, cohesive unit, even though it's
actually running on many independent machines. Distributed operating systems are
essential in systems like cloud computing, where resources are spread across many
machines, but users interact with the system as if it were one. Examples include Google’s
GFS (Google File System) and Amazon EC2. These systems are designed to handle the
complexity of network communication, synchronization, and error recovery.
The OS plays a critical role in the functioning of any computing system. It acts as a mediator
between users and hardware, ensuring efficient resource use, security, and system stability.
Without an OS, the hardware would be unusable, as there would be no mechanism for
managing tasks or interacting with devices. It simplifies software development by providing a
consistent environment for running applications. The OS also ensures that multiple processes
can run simultaneously, improving productivity. It manages system resources to prevent
conflicts and ensures that applications run smoothly. Overall, the OS is the backbone that
enables a computer to perform useful tasks efficiently.
Resource Allocation: The OS is essential in ensuring that all hardware resources are
used optimally without conflict.
Security: Without an OS, the system would be vulnerable to unauthorized access and
data breaches.
Ease of Use: An OS provides users with an easy way to interact with the computer,
manage files, and execute programs.
Program Execution: It manages the execution of programs, from loading into
memory to terminating.
Popular operating systems include Windows, used on personal computers for general-
purpose tasks, and macOS, which runs on Apple computers and is known for its design and
multimedia capabilities. Linux is an open-source OS used in servers, supercomputers, and
embedded systems due to its flexibility and security features. Android and iOS are mobile
operating systems used on smartphones and tablets, with Android being open-source and iOS
being proprietary. Each of these operating systems has specific features tailored to its target
device, ensuring that users can interact with their devices in an efficient and intuitive manner.
1. Windows 95 (1995):
o In 1995, Microsoft launched Windows 95, which marked a major turning point in the
OS landscape. It combined the capabilities of MS-DOS with a modern graphical user
interface (GUI) and introduced features like plug-and-play hardware support,
networking, and multitasking. It was designed for both home and business use,
offering a more user-friendly interface compared to previous versions of Windows.
o Windows 95 was a major commercial success and helped solidify the personal
computer as a common household item. It was the first OS to integrate the Internet
Explorer browser, laying the foundation for the internet revolution.
2. Windows NT (1993):
o Released in 1993, Windows NT (New Technology) was developed for businesses and
server environments. Unlike its consumer counterpart, Windows 95, Windows NT was
built to be a more stable and secure operating system, supporting advanced features
like preemptive multitasking and virtual memory.
o Windows NT would later evolve into Windows 2000 and Windows XP, becoming a
major foundation for modern Windows operating systems.
3. Linux (1991):
o In 1991, Linus To The history of operating systems rvalds released the first version of
Linux, a Unix-like operating system kernel. Linux was created as an open-source
alternative to proprietary systems like Windows and was designed to be freely
modifiable by anyone. Over the years, it gained widespread adoption due to its
stability, flexibility, and open-source nature.
o The 1990s saw the rise of Linux distributions, such as Red Hat Linux and Debian,
which helped Linux become a popular choice for server environments, especially in
web hosting and enterprise applications. This period also saw the development of the
GNU Project, which provided essential tools and software for Linux systems.
4. Mac OS (1990s):
o Apple's Mac OS went through a number of changes during the 1990s. While still based
on the classic Mac OS architecture, it was clear that it was falling behind in terms of
multitasking and modern features.
o In 1997, Apple hired Steve Jobs back, which led to the creation of Mac OS X, a Unix-
based operating system that would revolutionize Apple’s computing environment. Mac
OS X was officially released in 2001 but was in development during the late 1990s. It
combined the stability and performance of Unix with a polished, intuitive graphical
interface.
6. BeOS (1995):
o BeOS, developed by Be Inc., was another innovative OS in the 1990s. It was designed
for multimedia applications, offering fast performance and a clean GUI. While it
gained a small following, it never achieved widespread adoption and was eventually
acquired by Palm, Inc. in 2001.
2000 and Beyond: The Era of Modern OSes and Mobile Computing
1. Windows XP (2001):
o Released in 2001, Windows XP was one of the most successful operating systems in
Microsoft’s history. It was built on the Windows NT core and combined the stability
and features of the NT series with the user-friendly interface of Windows 95 and 98.
o Windows XP was praised for its speed, reliability, and compatibility, and it became the
standard OS for home and business computing for over a decade. Features like
Windows Media Center, Windows Firewall, and Windows Update made it a
comprehensive and easy-to-use platform.
2. Mac OS X (2001):
o In 2001, Apple introduced Mac OS X, a complete overhaul of the Mac OS, based on
NeXTSTEP (a Unix-like OS developed by Steve Jobs’ company NeXT). Mac OS X
integrated the stability and multitasking of UNIX with an elegant, user-friendly
graphical interface known as Aqua.
o Over time, Mac OS X became increasingly popular among developers and creative
professionals, thanks to its stability, intuitive design, and support for powerful
development tools.
Cloud Computing and the rise of mobile OS (iOS and Android) reshaped the
landscape of operating systems, moving beyond traditional desktop environments to
mobile-first, always-connected platforms.
Virtualization and containerization technologies like Docker and Kubernetes
furthered the idea of lightweight and efficient management of software environments.
Operating systems became more open-source with Linux, Android, and others
contributing to the wider tech ecosystem.
From the 1990s to 2000 and beyond, operating systems underwent significant transformations
driven by advances in hardware, networking, and the rise of mobile computing. The 1990s
saw a continued emphasis on GUI-based systems, while the 2000s introduced more
multitasking, networking, and mobile-first innovations. The era also witnessed the
development of modern OSes that cater to cloud, virtualization, and mobile device needs,
setting the stage for the future of computing.
Distributed Computing
1. Multiple Nodes:
o A distributed system consists of multiple computers or "nodes" that are geographically
dispersed and communicate over a network. Each node operates independently but
collaborates with others to solve a task.
o These nodes can be physical machines, virtual machines, or even containers in cloud
environments.
2. Resource Sharing:
o In distributed computing, resources such as processing power, memory, and storage
are shared across the network. This allows systems to pool their resources and function
as a more powerful unit than any individual node.
3. Scalability:
o Distributed computing systems can be scaled horizontally by adding more nodes
(machines) to the network. This ability to scale is a significant advantage over single-
computer systems, as it helps handle large amounts of data or a high number of tasks.
o It is easier to expand the system as demand grows by adding more resources or nodes.
4. Fault Tolerance:
o One of the key advantages of distributed systems is fault tolerance. If one node fails,
others can continue to operate and process the tasks. The system is designed in such a
way that failure in one part of the system does not bring down the entire system.
o Data is often replicated across nodes, ensuring that the failure of one node does not
result in data loss.
5. Transparency:
o Distributed systems aim to provide transparency to users, meaning the complexity of
the underlying system is hidden. For example, users can access remote resources as if
they were local, and can’t easily tell if data is stored on one machine or spread across
multiple machines.
6. Communication:
o Nodes in a distributed system communicate with each other via a network, often using
protocols like Remote Procedure Calls (RPC) or Message Passing Interface (MPI).
The communication layer enables data to be transferred between nodes, ensuring
synchronization and coordination in distributed tasks.
o This communication must be reliable and efficient to maintain system performance.
1. Client-Server Systems:
o A client-server model is one of the simplest forms of distributed computing, where
clients (users or applications) request services, and servers (specialized machines or
processes) provide them.
o This model is common in web applications, where users (clients) interact with web
servers to access resources, run applications, or store data.
3. Grid Computing:
o Grid computing is a form of distributed computing that involves pooling computing
resources from multiple locations (often across the world) to solve large-scale
computational problems. The grid behaves like a supercomputer, enabling scientists,
researchers, and engineers to perform resource-intensive computations.
o The resources in grid computing can be heterogeneous (running different hardware and
software) but are unified through software layers that make them work together.
4. Cloud Computing:
o Cloud computing is a model that provides on-demand computing services (like
storage, processing power, and networking) over the internet. Users can access remote
servers, data storage, and computational resources hosted in the cloud, typically
managed by a cloud provider like Amazon Web Services (AWS), Microsoft Azure,
or Google Cloud.
o Cloud computing systems are distributed by nature because they involve servers
spread across different geographical locations. Cloud platforms often use
virtualization to manage resources dynamically.
5. Cluster Computing:
o In a cluster computing model, multiple computers (often homogeneous) are
connected together to work as a unified system. Unlike grid computing, which
involves a more heterogeneous system of distributed resources, cluster computing
focuses on pooling similar resources to increase computational power and provide
redundancy.
o Clusters are often used for high-performance computing (HPC) applications that
require massive processing power, such as scientific simulations, data analysis, and
rendering.
1. Performance Improvement:
o By breaking a large task into smaller chunks and processing them in parallel,
distributed systems can achieve significant performance improvements over
traditional single-node systems.
2. Cost Efficiency:
o Distributed computing allows for the use of multiple machines, which may be
cheaper and easier to acquire compared to investing in a single, powerful machine.
This scalability is key in cloud computing, where users can rent computing resources
rather than invest in expensive hardware.
4. Scalability:
o Distributed systems are highly scalable because new nodes can be added to the
network as needed. This ensures that the system can handle increasing workloads and
data volumes.
5. Resource Sharing:
o Distributed systems allow for the sharing of resources like storage, processing power,
and bandwidth. This sharing helps optimize the use of available resources and
improves the overall efficiency of the system.
1. Synchronization:
o Keeping track of all the tasks and ensuring that data is correctly synchronized
across nodes can be complex. Distributed systems need mechanisms for data
consistency and synchronization to avoid errors or conflicts.
2. Security:
o With multiple nodes communicating over a network, security becomes a
significant concern. Protecting data in transit, preventing unauthorized access,
and ensuring the integrity of the system are all challenges in distributed
systems.
3. Network Issues:
o Since distributed systems rely on network communication, they can be
affected by network latency, congestion, or failures. This can impact the
performance and reliability of the system.
4. Complexity in Management:
o Managing a distributed system can be more complicated than managing a
single computer. Coordinating and monitoring multiple nodes, handling
failures, and ensuring proper communication are all added challenges.
4. Google Search:
o Google’s search engine operates on a distributed system, with multiple data centers
around the world indexing web pages and providing quick search results to millions of
users.
Parallel Computation
Parallelism is the core concept in parallel computation. It involves dividing a task into
smaller sub-tasks and executing them at the same time. There are two main types of
parallelism: task parallelism and data parallelism. Task parallelism is where different tasks or
operations are performed in parallel, while data parallelism applies the same operation to
multiple data elements at once. For instance, in data processing tasks like matrix
multiplication, each element can be computed simultaneously.
The memory architecture plays a crucial role in parallel systems. There are shared memory
systems where all processors have access to a common memory space, and distributed
memory systems where each processor has its own local memory. In shared memory systems,
processors communicate by reading and writing to the shared memory, while in distributed
systems, processors communicate via message passing. Both systems have their advantages
and challenges, especially concerning synchronization and managing access to memory.
Dataflow Model:
In the dataflow model, computation is driven by the flow of data. Operations are
triggered when the necessary input data becomes available, allowing for continuous
parallel execution without the need for explicit synchronization. In the dataflow
model, computation is driven by the availability of data. Operations are triggered
when input data becomes available, allowing parallel execution without needing
explicit synchronization. It is particularly useful for problems where tasks are
independent and can be executed as data flows through the system, enabling
continuous processing.
Hybrid Model:
In many modern systems, a combination of the above models is used to achieve
optimal performance. For example, large-scale distributed systems may use both
shared memory for local computations and message-passing for communication
between nodes. The hybrid model combines aspects of shared memory and message
passing models to optimize performance. For instance, a system may use shared
memory for local communication between processors and message passing for
communication between distributed nodes. This approach leverages the benefits of
both models for better scalability and efficiency.
Speedup: One of the most significant benefits of parallel computing is speed. By breaking
down a complex task into smaller sub-tasks and distributing them across multiple processors,
parallel computing can significantly reduce the time required to complete a computation. This
is especially useful in applications where processing large datasets or solving complex
problems would be time-prohibitive for a single processor. Tasks that would typically take
hours or days can be completed in a fraction of the time when processed in parallel, enabling
faster results and more efficient operations.
Cost Efficiency: Parallel computing allows for significant cost savings when compared to
traditional high-performance computing systems, such as supercomputers. Instead of
investing in expensive, specialized hardware, parallel systems can be built using multiple
smaller, off-the-shelf processors or cores. These processors work together to deliver high
performance, often at a fraction of the cost of more traditional supercomputing hardware.
This makes parallel computing a more accessible and cost-effective option for organizations
that need powerful computational resources without the high upfront investment.
Energy Efficiency: Parallel computing can also lead to energy savings. While it might seem
counterintuitive that using more processors would consume more energy, parallel systems
can actually be more energy-efficient than sequential processing. Since parallel systems
distribute tasks and complete them faster, they reduce the time that processors are active,
leading to less overall energy consumption. Additionally, parallel computing allows for more
efficient use of resources, as processors can be kept busy and utilized to their full potential
without running into bottlenecks that would waste time and energy in a sequential system.
Process
Definition of Process:
In the context of an operating system, a process is essentially a program that is actively being
executed by the system's hardware. During its execution, a process transitions through a
series of well-defined states, which represent the current status of the process at any given
time. These states are an important concept to understand, as they illustrate how the operating
system efficiently manages multiple processes, ensuring smooth and effective use of the
computer's resources. If you'd like to explore this topic in more depth, you can refer to the
concept of Processes in Operating Systems.
A process does not remain in the same state throughout its life cycle. Instead, it goes through
several stages, from creation to termination. In this article, we will delve into these states in
detail, providing a comprehensive understanding of how processes operate within an
operating system.
Process Lifecycle
When you execute a program, it transforms into a process and goes through various stages
before completing its execution. These stages, known as the process lifecycle, may differ
slightly across operating systems. However, the most commonly used models describe the
lifecycle as consisting of either two, five, or seven distinct states. Below is a simplified
explanation of these states:
1. Two-State Model: Focuses on basic states like Running and Not Running.
2. Five-State Model: Adds more granularity with states like New, Ready, Running, Waiting,
and Terminated.
3. Seven-State Model: Introduces additional states like Suspended Ready and Suspended
Waiting for more advanced scenarios.
Each of these states plays a crucial role in defining the journey of a process, from its creation
to its termination, and reflects how the operating system manages and schedules tasks.
Process States:
A process can exist in several states during its life cycle. These states reflect the different
stages a process goes through from creation to termination.
The Two-State Model provides the simplest view of a process's lifecycle, focusing on just
two states: Running and Not Running. Let’s explore each of these states in more detail:
1. Running:
When a process is in the Running state, it means the process is currently being executed
by the CPU. In this state, the process is actively performing its tasks, utilizing the
computer's resources (such as the CPU, memory, etc.) to carry out its instructions. This
state occurs when the operating system has scheduled the process to use the CPU, and the
process is working on its tasks, whether it’s performing calculations, processing data, or
interacting with external devices. The process will remain in the Running state until it
either completes its task or is interrupted for some reason, like a higher-priority process
requiring CPU time.
2. Not Running:
A process enters the Not Running state when it is not currently executing on the CPU.
There are several reasons why a process might be in this state:
o Waiting for Input: The process may be waiting for some form of external input, like
user interaction or data from an external device (such as a hard drive or network
connection). For example, a process that requires user input to continue might enter
this state while waiting for the user to provide the necessary information.
o Waiting for Resources: The process may also be waiting for a specific resource to
become available. For instance, if a process needs access to a file or a shared memory
location that is currently being used by another process, it must wait until that resource
is released.
o Paused or Blocked: In some cases, the process might be paused by the operating
system. This can happen due to various reasons, like lower priority compared to other
processes, or because it is blocked by some system event (such as waiting for a
network connection to respond).
o Completed or Terminated: Once a process finishes executing its instructions or
encounters an error, it moves to a state where it is no longer running. This could mean
the process has completed its task or has been terminated by the system.
Note for students: - Two-State Model helps us understand the fundamental nature of process
management by showing that processes either use the CPU to perform tasks (Running) or are
inactive, awaiting input or resources (Not Running). This simplicity is useful for
understanding the most basic level of process management but lacks the depth seen in more
complex models.
The Five-State Model provides a more detailed view of a process's lifecycle compared to the
simpler Two-State Model. While the Two-State Model assumes that all processes in the Not
Running state are ready to execute, the Five-State Model accounts for situations where a
process is temporarily unable to run because it is waiting for something—like user input or
data from an external device. To address this, the Not Running state in the Two-State Model
is divided into two distinct states, adding more precision to the process management. Here are
the five states in this model:
1. New:
The process enters the New state when it is first created but has not yet been admitted to
the system for execution. This is the stage where the operating system allocates resources
and prepares the process to be scheduled. At this point, the process is essentially in a
waiting queue before it gets the chance to move to the Ready state.
2. Ready:
Once the process has been created and is ready to run, it enters the Ready state. A process
in the Ready state is waiting for CPU time to be allocated to it by the operating system. It
is not currently executing, but it is prepared and waiting to be picked by the scheduler. In
systems with multiple processes, the scheduler determines the order in which processes
move from Ready to Running based on factors like priority or CPU availability.
3. Running:
A process enters the Running state when the operating system assigns the CPU to it.
During this state, the process actively executes its instructions using the CPU. The
process can remain in the Running state as long as it is not interrupted or does not finish
its task. If the process is preempted (e.g., due to a higher-priority task), it will return to the
Ready state.
4. Waiting (or Blocked):
In this state, the process is unable to proceed because it is waiting for some external event
to occur. For example, the process might be waiting for user input, data from an external
device, or for a file to become available. While in the Waiting state, the process is not
consuming CPU resources. It will remain in this state until the required event happens,
after which it can move back to the Ready state to await CPU time.
5. Terminated (or Exit):
The Terminated state indicates that the process has completed its execution or was
terminated due to an error or other factors. Once a process has finished its task, the
operating system releases its resources and removes it from the scheduling queue. If a
process encounters an error or is forcefully stopped by the system, it will also enter this
state. After termination, no further actions are performed by the process.
The Not Running state in the Two-State Model is divided into two separate states in
the Five-State Model: Waiting and Ready.
The addition of the New state introduces a step before a process becomes ready for
execution.
Note for students:- The Five-State Model offers a more nuanced view of process
management, enabling the operating system to more effectively manage processes that
require waiting for resources or external events. This model helps in maintaining the
efficiency of system operations by allowing the OS to make better decisions regarding when
to execute which process.
The Seven-State Model provides an even more detailed and complex view of the lifecycle of
a process. It expands on the earlier models by introducing additional states to account for
various scenarios, such as when processes are swapped in and out of memory, or when they
are waiting for I/O operations. Below is an explanation of the seven distinct states in this
model:
1. New State:
In the New state, a process is about to be created but has not yet been fully initialized
by the operating system. The program exists in secondary memory (like a hard drive)
and will eventually be picked up by the OS. The OS will then allocate necessary
resources and create the process in memory. This state is essentially the "waiting-to-
start" phase, where the process is preparing for execution but hasn’t started yet.
2. Ready State:
After a process is created, it moves into the Ready state. In this state, the process has
been loaded into the main memory (RAM) and is now ready to run. It is waiting for
the operating system to allocate CPU time for execution. The process doesn’t require
any resources other than the CPU to run. Multiple processes in the Ready state are
typically maintained in a Ready Queue, where the OS scheduler selects the next
process to run based on priorities or other scheduling algorithms.
3. Run State:
The process enters the Run state when it is selected by the operating system's
scheduler and assigned to the CPU for execution. During this state, the instructions of
the process are executed by the CPU. Once the process has been assigned to a CPU
core, it continues to run until it either completes its task, requires I/O, or is preempted
by a higher-priority process.
4. Blocked or Wait State:
When a process requires I/O or user input, or if it needs access to a critical resource
(such as a locked file), it enters the Blocked or Wait state. In this state, the process is
temporarily halted and cannot continue execution because it is waiting for some
external event or resource to become available. The process does not need CPU time
while in this state but remains in memory. Once the necessary I/O operation or
resource becomes available, the process transitions back to the Ready state.
5. Terminated or Completed State:
The Terminated state indicates that the process has finished its execution. At this
point, the operating system releases all resources that were allocated to the process,
including memory and file handles. The process is removed from the system, and its
control block (PCB) is deleted. If a process is forcefully killed due to errors or
external interruptions, it will also reach the Terminated state. No further operations
are performed on the process in this state.
6. Suspend Ready State:
A process enters the Suspend Ready state when it was previously in the Ready state
but was swapped out of the main memory by the operating system. This can happen if
the system runs out of physical memory (RAM) or if there is a need to free up space
for other processes. In such cases, the process is temporarily stored in secondary
memory (such as a hard drive) and will remain in the Suspend Ready state. The
process can transition back to the Ready state once it is brought back into the main
memory by the OS.
7. Suspend Wait or Suspend Blocked State:
This state is similar to the Suspend Ready state, but it involves processes that were
previously in the Blocked or Wait state. These processes are moved to secondary
memory because the system is low on available memory. These processes are waiting
for I/O operations to finish or some other resource to become available. Once the
required event is completed, the process may transition to the Suspend Ready state
before eventually returning to the Ready state.
CPU-Bound Processes: These are processes that primarily require CPU time for
computation. They perform a large number of CPU-intensive operations and rarely
need to interact with external devices or resources. These processes tend to run longer
in the Running state.
I/O-Bound Processes: These processes spend more time performing input/output
operations (such as reading from or writing to a file, waiting for network data, etc.)
than performing actual computations. I/O-bound processes are more likely to spend
time in the Blocked or Wait state, waiting for I/O operations to complete.
Key Differences:
Note for students:- the Seven-State Model is ideal for systems with advanced memory
management techniques, like virtual memory, and for operating systems that need to
efficiently manage a large number of processes.
Process Management
Process Management is a crucial function of an operating system, responsible for managing
processes during their entire life cycle. The operating system handles the creation,
scheduling, execution, and termination of processes. Efficient process management ensures
optimal CPU utilization, system responsiveness, and overall system stability. Below are the
key aspects involved in process management:
1. Process Creation:
The operating system is responsible for creating processes. This involves allocating
resources, such as memory and CPU time, and initializing the necessary data structures,
such as the Process Control Block (PCB), which holds information about the process,
including its state, program counter, CPU registers, and memory limits.
2. Process Scheduling:
The operating system must decide which process should be executed at any given time.
This is done through scheduling algorithms that determine the order of execution based
on factors like priority, process type, and fairness. Common scheduling strategies include
First-Come-First-Served (FCFS), Round Robin, and Priority Scheduling.
3. Process States:
Processes go through various states in their life cycle, including New, Ready, Running,
Waiting (Blocked), and Terminated (Exit). The operating system is responsible for
managing transitions between these states based on events such as CPU availability,
input/output completion, and process execution requirements.
4. Context Switching:
When the operating system switches from one process to another, it saves the state
(context) of the current process and restores the state of the next process to be executed.
This is known as a context switch. Context switching is essential for multitasking and
allows the system to run multiple processes seemingly simultaneously.
6. Process Termination:
Once a process has completed its task, it enters the terminated state. The operating
system cleans up resources allocated to the process, such as memory and file handles. If
the process terminates abnormally (due to errors or external interruption), the system
takes steps to handle the situation, such as generating error reports or logging the event.
Process State Transitions refer to the different stages a process goes through during its life
cycle and the transitions between these stages. These transitions are managed by the
operating system to ensure that processes are executed in an efficient and controlled manner.
Understanding these state transitions is key to how the operating system schedules and
manages processes.
1. New (Created):
This is the initial state of a process when it is first created. In this state, the operating
system allocates the necessary resources (such as memory, CPU time, and others) for the
process to begin its execution. The process is set up, and a Process Control Block (PCB)
is created to track its information.
Transition: From New to Ready, once the process is ready to be scheduled for
execution but is waiting for the CPU to become available.
2. Ready:
A process in the Ready state is waiting for the CPU to be assigned to it for execution. It
has all the resources it needs (such as memory, files, etc.) except the CPU. The operating
system's scheduler selects processes from the ready queue and assigns CPU time based
on scheduling algorithms (e.g., First-Come-First-Served, Round Robin, etc.).
Transition: From Ready to Running, when the CPU becomes available and the
process is selected to execute.
3. Running:
A process in the Running state is currently being executed by the CPU. The process is
actively using the processor and performing its tasks. The CPU executes instructions from
the process, and the program counter is updated during this time.
Transition: From Running to Waiting, if the process needs to wait for some event or
resource (such as I/O operations).
4. Waiting (Blocked):
A process enters the Waiting state when it needs to wait for an event or resource (such as
data from a disk or completion of an I/O operation) before it can continue execution.
While in this state, the process is not eligible for CPU time and is essentially blocked
from running until the event or resource is available.
Transition: From Waiting to Ready, once the required event or resource is available,
allowing the process to resume execution.
5. Terminated (Exit):
The process reaches the Terminated state when it has completed its execution or is
terminated due to an error or external interruption.
Summary of Transitions:
New → Ready: Process is ready for scheduling but is waiting for CPU allocation.
Ready → Running: CPU is assigned to the process for execution.
Running → Waiting: Process is waiting for an external event (like I/O).
Running → Ready: Process is preempted or voluntarily gives up the CPU.
Waiting → Ready: Process is ready to resume execution after the event or resource is
available.
Running → Terminated: Process completes execution and exits.
The Process Control Block (PCB) is a crucial data structure used by the operating system to
store information about each process during its execution. The PCB is created when a process
is first created and is used throughout the life cycle of the process to manage and track its
execution. It acts as a repository for process-specific information that is necessary for the
operating system to schedule and manage processes.
1. Process ID (PID): The unique identifier assigned to the process by the operating system.
It distinguishes this process from others in the system.
2. Process State: The current state of the process (e.g., running, ready, waiting, terminated).
This helps the operating system understand the process’s status in its life cycle.
3. Program Counter (PC): The program counter stores the address of the next instruction
that is to be executed. When a process is switched out, the operating system saves the
program counter value, so it can resume execution from the same point later.
4. CPU Registers: These are the values of the CPU’s registers (such as general-purpose
registers, accumulator, stack pointer, etc.) that the process was using. These are saved in
the PCB when the process is interrupted, so they can be restored when the process is
resumed.
5. Memory Management Information: Information about the memory allocated to the
process, including the base and limit registers, page tables, or segment tables. This allows
the operating system to properly manage the memory resources for each process.
6. Scheduling Information: Information that helps the operating system to schedule the
process, such as the priority of the process, pointers to scheduling queues, and other
scheduling-related data. This is essential for process scheduling and decision-making.
7. I/O Status Information: Details about the I/O devices allocated to the process, including
a list of open files, I/O devices the process is using, and other relevant data. It helps the
OS manage I/O operations for the process.
8. Process Ownership: Information about the process owner, such as user ID (UID) and
group ID (GID), which helps the operating system track the resources used by different
users and ensures proper access control.
9. Accounting Information: Includes resource usage statistics such as CPU time consumed
by the process, memory usage, number of I/O operations, and other performance-related
information. This is often used for process accounting and optimization.
10. Process Privileges: Information about the privileges granted to the process, such as
permissions to access certain system resources or perform privileged instructions.
Context Switching:
The PCB allows for efficient context switching between processes. When a process is
preempted or suspended, the operating system saves the state of the process (program
counter, registers, etc.) in the PCB. When the process resumes execution, the operating
system can restore the saved state from the PCB and continue from where the process left
off.
Process Management:
The PCB holds all the information necessary for managing processes, such as their state,
memory, and scheduling information. The operating system uses the PCB to track the
execution state of each process.
Resource Allocation:
The PCB stores information about which resources (CPU, memory, I/O devices) are
allocated to the process. The operating system uses this information to ensure that
resources are used efficiently and are freed when the process terminates.
Process Synchronization and Communication:
The PCB also contains information for process synchronization and inter-process
communication, helping processes interact with each other and avoid conflicts over
shared resources.
Operation on a Process
The execution of a process is a complex activity. It involves various operations. Following
are the operations that are performed while execution of a process:
The execution of a process in a computer system involves a series of complex operations that
enable the system to manage processes efficiently. These operations ensure that multiple
tasks can be handled concurrently without causing crashes or significant slowdowns. Below
is a breakdown of the key operations involved in process execution:
1. Creation
Process creation is the first step in the process execution lifecycle. It involves the creation of
a new process that is ready for execution. The process can be initiated by the operating
system, a user, or even by another process. Events that lead to the creation of a new process
include:
The operating system creates several background processes during system startup.
A user requests the creation of a new process, often through executing a program or
command.
A running process can create a new process as part of its execution, commonly known as
process spawning.
A batch job initiation triggers the creation of multiple processes in batch processing
systems.
2. Scheduling/Dispatching
Scheduling and dispatching refer to the activity where the operating system transitions a
process from the ready state to the running state. This occurs when resources are available, or
when a process has a higher priority than the currently running process. Key scenarios that
trigger scheduling/dispatching include:
The availability of CPU time for processes that are in the ready state.
A higher-priority process is ready to execute, preempting a currently running process.
The operating system manages time-sharing by switching between processes based on
priority and resource availability.
3. Blocking
Blocking occurs when a process requests an input/output operation that cannot proceed
immediately, causing the operating system to block the process. In this state, the process is
put into a "waiting" state until the requested operation (such as reading from a disk or waiting
for user input) is completed. This ensures the CPU can be used by other processes that are
ready to execute. Blocking events typically occur when:
A process performs an I/O operation, like reading data from a file or network.
The operating system must wait for external resources to become available.
The process is temporarily suspended while awaiting results or responses.
4. Preemption
Preemption occurs when a process is forced to relinquish the CPU before it finishes its
execution. This typically happens in systems that support preemptive scheduling, where
processes are assigned time slices or timeouts. Preemption ensures that higher-priority tasks
can gain access to the CPU. It occurs in the following scenarios:
A process exceeds its allocated time slice, causing the operating system to preempt it in
favor of other processes.
A high-priority process enters the ready state, prompting the operating system to preempt
a lower-priority process.
The operating system reassigns CPU time to ensure fair distribution of resources among
processes.
5. Process Termination
Process termination is the final phase in a process's lifecycle, where it ceases execution and
releases the resources it had allocated. Various events can lead to process termination, such
as:
The process completes its execution successfully and notifies the operating system that it
is finished.
The operating system terminates the process due to errors or system faults.
Hardware failures or other critical issues can cause the process to terminate unexpectedly.
Imagine a system with several processes stored in the Process Control Block (PCB). Each
process utilizes the CPU to perform its operations. However, other processes with higher
priority may need to use the CPU to complete their tasks. This is where context switching
comes into play.
In this scenario, when the operating system decides to switch from one process to another, it
first saves the context (the state, including CPU registers and memory information) of the
current process in its PCB. The operating system then loads the context of the next scheduled
process from its PCB, resuming its execution from where it was paused.
This switching between processes allows the system to manage multiple tasks in an efficient
manner, ensuring that the CPU is fully utilized. However, it's important to note that the
process of switching the CPU from one process to another is an overhead operation, meaning
that no useful work is done during this time.
Context-switch times typically take a few milliseconds, but this varies depending on factors
such as hardware support, memory speed, and the complexity of the operating system. Some
processors may have specialized hardware features that make context switching more
efficient, such as multiple sets of registers, which allows for faster switching.
Context switching is vital for enabling multitasking, allowing multiple processes to share a
single CPU while maintaining their own execution states. Here are some key reasons why
context switching is necessary:
1. Sharing CPU Resources: Since most systems have a single CPU, context switching
enables multiple processes to take turns using the CPU, giving the illusion that all
processes are running simultaneously.
2. Process Continuity: When a process is interrupted, context switching ensures that it can
be resumed later from the exact point it was paused. This is essential for maintaining the
continuity of process execution.
3. Efficient Resource Utilization: By allowing the CPU to be shared among processes,
context switching ensures that the system operates efficiently, maximizing the usage of
available CPU resources.
4. Multitasking with a Single CPU: Context switching allows a single CPU to handle
requests from multiple processes in parallel, without the need for additional processors.
This makes it possible for a system to execute several tasks concurrently, improving
overall system performance.
Context switching can be triggered by several events. The three main categories of context-
switching triggers are:
1. Interrupts: These occur when external devices (like disk drives or network interfaces)
send signals to the CPU to request its attention. For example, if a process is running and
the CPU needs to read data from a disk, an interrupt can trigger a context switch so the
CPU can handle the disk I/O operation. Once the I/O is completed, the CPU returns to the
process that was interrupted.
2. Multitasking: The ability of the operating system to switch between processes is at the
heart of multitasking. When a process is running, the operating system may decide to
suspend it temporarily and load another process to execute. This switching ensures that
multiple processes can execute concurrently on the CPU, giving the illusion of
parallelism.
3. Kernel/User Switch: This trigger occurs when the operating system switches between
user mode and kernel mode. User mode is where regular application processes run, while
kernel mode is reserved for the operating system’s core functions. A context switch is
required to switch between these two modes, allowing the operating system to interact
with hardware and perform low-level tasks.
Important note for students: - Context switching plays a critical role in managing the
execution of processes in an operating system. It ensures that multiple processes can run on a
single CPU by saving and restoring their states, enabling the system to handle multitasking
efficiently. The process involves overhead, as the CPU must save and load contexts, but it is
necessary to make effective use of CPU resources. Context switching is triggered by events
such as interrupts, multitasking, and kernel/user mode switching, and its efficiency depends
on factors like hardware support and system architecture. Understanding context switching is
key to optimizing operating system performance and ensuring smooth execution of multiple
processes in modern computing systems.
In I/O devices, the processor uses a special bus control line, known as the Interrupt Service
Routine (ISR), to handle interrupt requests. The ISR is a piece of code in the operating
system designed to deal with the interrupt. The processor must immediately recognize and
process the interrupt when it occurs.
When a device sends an interrupt signal to the processor, the following sequence of actions
takes place:
Interrupt Latency
One important factor associated with interrupt handling is interrupt latency. This is the time
delay between the moment an interrupt is raised and the start of the execution of the
corresponding Interrupt Service Routine. Several factors contribute to interrupt latency,
including:
Interrupt Acknowledgement: The processor must first recognize and acknowledge the
interrupt request, which can take time.
Saving Process State: Before handling the interrupt, the processor must save the current
process's state, including the values in the CPU registers and the Program Counter, to
ensure it can resume the process later.
Context Switching: If the interrupt triggers a context switch (i.e., switching to a different
process or kernel mode), additional overhead is added to the interrupt latency.
Interrupt Priority: If multiple interrupts occur simultaneously or in quick succession,
the processor may need to prioritize them, leading to delays in handling some interrupts.
Interrupt Classes
Interrupts are essential for managing the execution of processes in an operating system,
allowing the system to respond promptly to critical events. They can be classified into six
major classes, each serving a different purpose in managing system resources, hardware, and
software. Here is an overview of the six interrupt classes:
SVC interrupts are generated by the running process, typically in user space, to request
specific system services from the operating system. These services may involve critical
operations like input/output tasks, allocating more system resources (such as memory), or
communicating with the system administrator. In simpler terms, an SVC interrupt is a method
used by a process to transition from user mode to kernel mode, enabling it to access higher-
privileged system operations.
Example:
A program requests the operating system to perform a disk read operation, which triggers
an SVC interrupt to transfer control to the kernel for execution.
2. I/O Interrupts
I/O interrupts are generated by input/output (I/O) devices to signal the completion of an
operation, such as finishing a disk read or write, or reporting an error condition. These
interrupts notify the processor that it can resume the next step in the operation or handle a
failure. I/O interrupts are crucial for enabling efficient asynchronous communication between
the CPU and peripheral devices.
Example:
A hard disk sends an I/O interrupt to indicate that it has finished reading data and the
CPU can process the information.
3. External Interrupts
External interrupts are typically caused by events that originate outside of the processor or its
immediate environment. These events may include the expiration of a timer or clock
interrupt, signals from other processors in a multiprocessor system, or hardware-level signals
that require immediate attention. External interrupts can occur at unpredictable times and
usually require prompt action from the CPU to ensure system stability.
Example:
The expiration of a time slice in a time-sharing system might trigger an external interrupt
to notify the operating system that a process must be preempted in favor of another
process.
4. Restart Interrupts
Restart interrupts are initiated when a specific action requires the processor to restart its
execution. This may be due to an operator manually pressing a restart button or receiving a
restart signal from another processor in a multiprocessor system. The restart interrupt is often
used to recover from errors, reinitialize the system, or start a fresh round of execution.
Example:
A hardware failure or a software crash might lead the system to request a restart using a
restart interrupt.
Program check interrupts occur when the processor encounters an issue while executing a
program. These issues often involve errors in the program's logic, such as trying to divide by
zero, causing an arithmetic overflow or underflow, referencing an invalid memory location,
or attempting to perform an illegal operation. A program check interrupt signals the operating
system to handle the error, typically by halting or debugging the program.
Example:
Machine check interrupts are caused by malfunctions in the hardware itself. These types of
interrupts are typically triggered when a hardware component, such as the CPU, memory, or
peripheral devices, experiences a failure. Machine check interrupts are crucial for detecting
hardware faults and notifying the operating system or system administrator so that corrective
actions can be taken.
Example:
A faulty memory module sends a machine check interrupt, notifying the operating system
of the error so that appropriate recovery steps can be initiated.
Read it if you want :- Interrupts serve as a fundamental mechanism that allows operating
systems to manage and respond to critical events efficiently. The six classes of interrupts—
SVC, I/O, external, restart, program check, and machine check—cover a wide range of
system and process management activities. Understanding how these interrupt classes work
helps in the development of reliable and efficient systems that can handle various hardware
and software events with minimal disruption to ongoing processes.
Interrupt Processing
Interrupt processing is a critical feature of modern operating systems, enabling the system to
efficiently respond to external or internal events. An interrupt temporarily halts the ongoing
execution of a program and transfers control to the operating system to handle the event that
triggered the interrupt. This mechanism ensures that the system can manage multiple
processes concurrently, even when hardware or software events demand immediate attention.
1. Interrupt Occurrence
o An interrupt can be initiated either by a hardware event (such as I/O completion or
a hardware malfunction) or a software-generated request (trap or system call). The
interrupt may be synchronous (triggered by the running process) or
asynchronous (triggered by an event unrelated to the current process).
2. Operating System Gains Control
o Once an interrupt occurs, the operating system immediately takes control of the
CPU. The current process is temporarily suspended, and the system switches to a
special mode to handle the interrupt.
3. Saving the State of the Interrupted Process
o The state of the interrupted process (such as the contents of CPU registers,
program counter, etc.) is saved to a specific data structure, usually the Process
Control Block (PCB) of the process. This step ensures that the process can be
resumed later from the exact point where it was interrupted without any loss of
data or progress.
4. Interrupt Analysis and Routing
o After saving the state of the interrupted process, the operating system determines
the cause of the interrupt. This involves checking the interrupt vector (a table of
addresses) to identify which specific interrupt handler needs to be invoked to
handle the interrupt.
5. Interrupt Handler Execution
o The operating system passes control to the interrupt handler routine. The
interrupt handler is a special piece of code that processes the interrupt, such as
managing the I/O operation, handling hardware failures, or responding to a timer
signal. The handler executes the necessary steps to resolve the event that triggered
the interrupt.
6. Restoring the State of the Interrupted Process
o Once the interrupt has been processed, the operating system restores the saved
state of the interrupted process from its PCB. This includes restoring the values of
the CPU registers and program counter.
7. Resuming the Interrupted Process
o After restoring the process's state, the system resumes execution of the interrupted
process as if it had not been interrupted. The process continues executing from the
exact point where it was paused, ensuring seamless operation.
Types of Interrupts
Note: - Interrupt processing enables the efficient execution of multiple tasks in an operating
system, ensuring that high-priority events are handled immediately without causing
unnecessary delays. By saving the state of the interrupted process, analyzing the interrupt,
executing the appropriate handler, and resuming the process, the operating system ensures
smooth multitasking and responsiveness to system events. The handling of synchronous and
asynchronous interrupts is central to the system’s ability to manage multiple processes
concurrently and efficiently.
communication signals
In an operating system (OS), communication signals are a fundamental mechanism for inter-
process communication (IPC). Signals allow processes to send notifications or alerts to each
other, helping to coordinate their actions, handle exceptions, or respond to system events. A
signal is essentially an interrupt sent to a process or the OS to inform it of an event that
requires immediate attention. These events might be a request to terminate a process, a
request to stop a process temporarily, or notifications about system errors, among others.
In UNIX-based operating systems, such as Linux or macOS, signals play a crucial role in
process management. Signals are asynchronous notifications that can be sent to a process by
the operating system or another process. When a process receives a signal, it can either
handle the signal, ignore it, or take the default action defined by the operating system. For
instance, if a process receives the SIGINT signal (typically generated by pressing Ctrl+C), the
default action is to terminate the process. However, a process can intercept this signal and
take an alternative action, such as cleaning up resources before exiting.
Signals are generally asynchronous, meaning that they can occur at any point during the
execution of a process. When a process receives a signal, the operating system temporarily
interrupts its current execution and transfers control to a signal handler, if one is defined. The
signal handler is a small piece of code that defines how to handle the specific signal, whether
it is to terminate the process, ignore it, or perform some other action. If the process does not
define a handler for a particular signal, the OS will take the default action associated with that
signal. For instance, when a process receives a SIGSEGV signal due to an invalid memory
access, the OS might terminate the process immediately. Alternatively, if the process receives
a SIGTERM signal, it might choose to clean up resources, log an exit message, or prompt the
user for confirmation before terminating.
A process can send a signal to another process using system calls like kill() in UNIX-based
systems. Despite its name, kill() is not just used to terminate processes; it can be used to
send any signal, including signals to pause, resume, or notify processes of certain events. The
signal sent using kill() could be something as simple as notifying a process to update its
status, or something more serious like notifying a process that it needs to terminate due to an
error. On the receiving side, processes can handle signals in different ways. If a process is in
a critical section and cannot be interrupted, it may block certain signals temporarily to
prevent interruption. It can also choose to ignore certain signals altogether or catch them to
perform custom handling. Signal handling can be defined using system calls like signal() or
sigaction() in UNIX-based systems, which allow processes to define custom handlers for
specific signals.
Processes can use signal masks to control which signals they want to accept or ignore. A
signal mask is a bitmask that indicates which signals are blocked. A blocked signal will not
be delivered to the process until it is unblocked. Signal masking is useful when a process is in
the middle of performing a critical task and doesn't want to be interrupted by certain signals.
Once the critical section is complete, the process can unblock the signals and process them.
Signals are efficient and lightweight for handling simple notifications between processes or
between the OS and a process. They don't require complex data transmission and can be
triggered by events such as user input, errors, or system calls. For example, signals like
SIGINT and SIGTERM are used for process control, allowing a user or system to interrupt or
terminate a process without having to interact with the process directly.
Moreover, signals enable asynchronous event handling. This means that processes don't need
to constantly check for conditions or poll for changes. Instead, the operating system sends a
signal when an event occurs, allowing the process to handle the event as soon as possible.
Limitations of Signals
While signals are useful for simple communication and process control, they do have
limitations. One key limitation is the limited amount of information a signal can carry. A
signal typically only informs the recipient process of an event, but it does not carry detailed
data or information about the event. For example, when a process receives a SIGTERM signal,
it only knows that it is being asked to terminate, but it doesn't know why or who is requesting
the termination.
Additionally, signals are generally not suitable for transmitting large or complex amounts of
data between processes. For tasks that require more sophisticated communication, other IPC
mechanisms such as message queues, shared memory, or sockets are used.
Message passing refers to the method by which data or information is transferred between
two or more processes. It provides a way for processes to communicate, ensuring that the
data exchanged is delivered to the correct destination. In a message-passing system, processes
do not share memory directly; instead, they send and receive messages via communication
channels provided by the operating system.
1. Direct Communication: The sender knows the identity of the receiver and can directly
send a message.
2. Indirect Communication: The sender sends a message to a mailbox or a message queue,
and the receiver retrieves the message from it.
1. Message Queues:
o A message queue is a queue-like structure that holds messages before they are
received by the destination process. In most systems, message queues provide the
basic mechanism for message passing. Each message in the queue is retrieved in
the order it was added, often following a First-In-First-Out (FIFO) policy.
2. Mailboxes:
o A mailbox is a communication channel where processes can send and receive
messages. Each mailbox can hold messages sent by different processes, and the
recipient process retrieves messages from the mailbox. It can be thought of as a
buffer where messages are stored temporarily until they are received.
3. Pipes:
o Pipes are another form of inter-process communication that is often used in a
producer-consumer scenario. Data written by one process can be read by another
process through a pipe. Pipes are typically used for communication between
processes within the same system, and they can be either anonymous (for parent-
child relationships) or named (for communication between any two processes).
4. Sockets:
o Sockets provide communication over a network, allowing processes on different
machines to exchange messages. They provide an endpoint for sending and
receiving messages, and they are typically used for communication in distributed
systems. Sockets can be used for both synchronous and asynchronous message
passing.