OS - Lect 6
OS - Lect 6
Lecture 6
Interrupts
What is an Interrupt?
In the case of an interrupt, the system informs the CPU that it needs attention
While in polling, the CPU constantly inspects the status of the system to find
whether it needs attention.
In Polling
you pick up the phone every few seconds to check whether you are getting a
phone
In interrupt:
do whatever you should do and pick up the phone every when it is rings.
Difference between Interrupt and Polling
In Polling Polling is an affair that informs the CPU that a system
int main()
{
needs its attention. It is a constant action to find out whether
while(1) the system is working efficiently and properly.
{
int count = 1;
while(count < 500000)
count++;
toggle(PIN_5);
}
return 0;
}
S.No
Interrupt Polling
1. When it comes to an interrupt, the device When it comes to polling, the CPU keeps on checking if the
informs the CPU that it needs its attention. device needs attention.
3. It can occur at any time and moment. Here the CPU polls the system at some particular intervals.
1- Hardware Interrupts
An electronic signal sent from an external device or hardware to
communicate with the processor indicating that it requires
immediate attention. For example, strokes from a keyboard or
an action from a mouse invoke hardware interrupts causing the
CPU to read and process it. So it arrives asynchronously and
during any point of time while executing an instruction.
• For example (Key press by the user, e.g. CTRL ALT DEL)
1. Maskable Interrupt :
An Interrupt that can be disabled or ignored by the instructions of CPU are
called as Maskable Interrupt.
1. Non-Maskable Interrupt :
An interrupt that cannot be disabled or ignored by the instructions of CPU
are called as Non-Maskable Interrupt. A Non-maskable interrupt is often
used when response time is critical or when an interrupt should never be
disable during normal system operation. Simply is the highest priority
activities that need to be processed immediately and under any situation.
Hardware Interrupts (Maskable and Non-Maskable)
SR.N
O. Maskable Interrupt Non Maskable Interrupt
A non-maskable interrupt is a hardware interrupt
Maskable interrupt is a hardware Interrupt that can
1 that cannot be disabled or ignored by the
be disabled or ignored by the instructions of CPU.
instructions of CPU.
When non-maskable interrupts occur, the current
When maskable interrupt occur, it can be handled
2 instructions and status are stored to handle the
after executing the current instruction.
interrupt.
Maskable interrupts used to interface with Non maskable interrupt used for emergency
3
peripheral device. purpose e.g power failure, smoke detector etc .
4 In maskable interrupts, response time is high. In non maskable interrupts, response time is low.
5 Operation can be masked or made pending. Operation Cannot be masked or made pending.
Types of Interrupt (Hardware / Software Interrupts)
2- Software Interrupts
• The processor itself requests a software interrupt after executing certain
instructions or if particular conditions are met.
Examples
• division by zero or invalid memory access
• A cout (or) cin statement in C++ would generate a software interrupt
because it would make a system call to print something
Interrupt Handling
1. CPU is interrupted
2. CPU stops current process
3. CPU transfers execution to a fixed location
4. CPU executes interrupt service routine
5. CPU resumes process
• Notes:
• Interrupts must be handled quickly
• Interrupted process information must be stored
Interrupt Handling Mechanisms
• Variable initialization
• open ( file1 )
• create ( file2 )
• read ( file1 )
• write ( file2 )
• close ( file1 )
• close ( file2 )
Example of System Calls
• System call sequence to copy the contents of one file to
another file
Types of System Calls
• Process control
• File management
• Device management
• Information maintenance
• Communications
Types of System Calls
• Process control
• create process, terminate process
• end, abort
• load, execute
• get process attributes, set process attributes
• wait for time
• wait event, signal event
• allocate and free memory
• Dump memory if error
• Debugger for determining bugs, single step execution
• Locks for managing access to shared data between
processes
Types of System Calls
• File management
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes
• Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices
Types of System Calls (Cont.)
• Information maintenance
• get time or date, set time or date
• get system data, set system data
• get and set process, file, or device attributes
• Communications
• create, delete communication connection
• send, receive messages if message passing model to host
name or process name
• From client to server
• Shared-memory model create and gain access to memory
regions
• transfer status information
• attach and detach remote devices
System Calls Types
allocate memory
free memory
Examples of Windows and Unix System Calls
Ref: https://www.guru99.com/system-call-operating-system.html
Ref: https://www.javatpoint.com/system-calls-in-operating-system
Ref: https://www.geeksforgeeks.org/introduction-of-system-call/
Deadlocks
Table of Content
• Introduction
• Deadlock Characterization
• Methods for Handling Deadlocks
• Deadlock Prevention
• Recovery from Deadlock
introduction
The Deadlock Problem
P1 P2
wait (A); wait(B)
wait (B); wait(A)
Is this Deadlock?
Yes, How to prevent it?
Bridge Crossing Example
• Process
Pi Rj
• Pi requests instance of Rj
Pi Rj
• Pi is holding an instance of Rj
Example of a Resource Allocation Graph
Resource Allocation Graph With A Deadlock
Resource Allocation Graph With A Cycle But No Deadlock
Basic Facts
• deadlock avoidance
• deadlock prevention
• deadlock ignorance
Deadlock avoidance
deadlock avoidance
• Mutual Exclusion
• Not required for sharable resources; must hold for non-sharable
resources.
• Circular Wait
• Impose a total ordering of all resource types, and require that each
process requests resources in an increasing order of enumeration.
Detection and Recovery from
Deadlock
Detection and Recovery from Deadlock
• This approach let the processes fall in deadlock and then
periodically check whether deadlock occur in the system or not.
• With DMA, the CPU can process other tasks while data transfer is
being performed. The transfer of data is first initiated by the CPU.
The data block can be transferred to and from memory by the
DMAC in three ways.
Direct Memory Access Structure