Assignment 2 OS
Assignment 2 OS
Page | 1
Question 1: What is the purpose of interrupts? How does an interrupt differ
from a trap? Can traps be generated intentionally by a user program? If so,
for what purpose?
Answer:
Purpose of Interrupts
Interrupts are mechanisms that temporarily halt the normal execution of a program
to allow the CPU to respond to urgent events. Their main purpose is to improve
system e iciency by enabling the CPU to handle multiple tasks without constantly
checking for events (polling). Interrupts are crucial in various aspects of computing,
including:
Handling I/O operations: Devices such as keyboards, mice, and disk drives
generate interrupts to notify the CPU when they require attention. For
example, when a user presses a key, an interrupt is sent to the CPU to
process the input.
Error handling: Interrupts are also used to handle critical errors such as
memory access violations, illegal instructions, or divide-by-zero errors,
ensuring that the system can take appropriate action instead of crashing.
Both interrupts and traps are mechanisms that cause a temporary pause in a
program’s execution to allow the operating system to take control. However, they
di er in several ways:
Interrupts:
Page | 2
o Typically generated by external hardware devices, such as I/O
peripherals, timers, or network interfaces.
Traps:
Yes, user programs can intentionally generate traps for several important purposes:
1. System Calls:
o Traps are commonly used to invoke system calls, which allow user
programs to request services from the operating system.
o In Linux, system calls like read(), write(), and fork() are implemented
using software interrupts or trap instructions.
2. Exception Handling:
Page | 3
o Some programming languages and systems use traps to handle
exceptions.
3. Debugging:
o For example, when using gdb, a trap is set at a specific instruction, and
execution is interrupted when that instruction is reached, enabling
step-by-step debugging.
In summary, while both interrupts and traps serve as mechanisms for handling
events that require immediate attention, interrupts are mainly triggered by
hardware, while traps are software-generated. User programs intentionally use traps
to access system services, handle exceptions, and assist with debugging.
Page | 4
Question 2: How do clustered systems differ from multiprocessor systems?
What is
required for two machines belonging to a cluster to cooperate to provide
a highly available service?
Answer:
Di erence Between Clustered Systems and Multiprocessor Systems
Both clustered and multiprocessor systems involve multiple computing units
working together, but they di er in architecture and purpose:
Multiprocessor Systems:
o Contain multiple CPUs within a single system, sharing memory and
other resources.
o CPUs are tightly coupled and communicate through shared memory.
o Designed to improve performance by enabling parallel processing and
load balancing within a single machine.
o Common in high-performance computing and enterprise servers.
Clustered Systems:
o Consist of multiple independent computers (nodes) connected via a
high-speed network.
o Nodes work together to perform tasks and can provide fault tolerance
and scalability.
o Unlike multiprocessor systems, nodes do not share memory but
communicate via network-based messaging protocols.
o Used in cloud computing, web hosting, and high-availability services.
Requirements for Cooperation in a Clustered System
For two machines in a cluster to cooperate and provide a highly available service,
they must meet several key requirements:
1. Network Communication:
o A fast and reliable network is essential for e icient communication
between nodes.
o Technologies such as Ethernet, InfiniBand, or fiber-optic connections
are commonly used.
2. Shared Storage or Data Synchronization:
o Nodes need access to the same data to ensure consistency.
o This can be achieved through a shared storage system (e.g., Network-
Attached Storage (NAS) or Storage Area Network (SAN)) or data
replication mechanisms.
3. Load Balancing:
o A load balancer distributes client requests across multiple nodes to
optimize performance and prevent overloading.
Page | 5
o Techniques include round-robin scheduling, least connections, or
dynamic resource allocation.
4. Failover Mechanism:
o If one node fails, another must take over its workload seamlessly.
o This requires heartbeat monitoring (to check node health) and
automatic failover mechanisms.
5. Cluster Management Software:
o Software like Kubernetes, Apache Hadoop, or Microsoft Failover
Clustering helps manage workloads and automate resource allocation.
6. Consistency and Synchronization:
o Databases and application states must remain synchronized across
nodes to prevent inconsistencies.
o Techniques like distributed databases, quorum-based consistency, or
synchronization protocols (e.g., Paxos, Raft) help maintain data
integrity.
Conclusion
Multiprocessor systems improve computing power within a single machine,
whereas clustered systems consist of multiple independent machines working
together. To achieve high availability, clustered systems rely on network
communication, shared storage, load balancing, failover mechanisms, and cluster
management software.
The End
Page | 6