OS - Lecture 02 Operating System
OS - Lecture 02 Operating System
CC-311 / CC-217
Department of Information Technology, Faculty of Computing and IT, University of the Punjab, Gujranwala Campus
Agenda for Today
• Interrupts
• Traps
• Signal
• Hardware (I/O, Memory, and CPU) Protection
Interrupts
An interrupt is a signal generated by a hardware device
(usually an I/O device) to get CPU’s attention.
Interrupt transfers control to the interrupt service routine
(ISR), generally through the interrupt vector table, which
contains the addresses of all the service routines.
Interrupt architecture must save the address of the
instruction after the interrupted instruction and the CPU state
so that execution of the interrupted process may continue
after the interrupt has been serviced.
Incoming interrupts are disabled while another interrupt is
being processed to prevent a lost interrupt.
Traps
A trap (or an exception) is a software-generated interrupt
caused either by an error or by a user request for an
operating system service.
Signals
A signal is an event generated to get attention of a process.
The signal generated in this case is called SIGINT (Interrupt
signal).
Three actions are possible on a signal:
Kernel-defined default action
Process can intercept the signal and ignore it
Process can intercept the signal and take a programmer-
defined action
Hardware Protection
Dual Mode Protection
I/O Protection
Memory Protection
CPU Protection
Dual Mode Operation
Sharing system resources requires operating system to
ensure that an incorrect program cannot cause other
programs to execute incorrectly.
Provide hardware support to differentiate between at least
two modes of operations.
User mode - execution done on behalf of a user.
Monitor mode (also kernel mode or system mode) -
execution done on behalf of operating system.
Mode bit added to computer hardware to indicate the current
mode: monitor (0) or user (1).
I/O Protection
All I/O instructions are privileged instruction.
When a CPU is executing in a user mode, it is not allowed to
execute these privileged instructions. If it try to do it, a trap
will be generated and program will be terminated.
This is because we don’t want a user process to hold device
directly.
So, I/O will be done using system call.
Memory Protection
Memory Address Space
The area where the process is loaded into the main
memory is called memory address space
By implementing memory protection, we want to make sure
that no process can access memory space outside its
Process Address Space
This is because we don’t want a user process to hold device
directly.
To implement memory protection, usually two registers are
used:
Base Register - holds the smallest legal physical memory
address.
Limit Register - contains the size of the process.
Memory Protection
Memory Protection
CPU Protection
Timer – interrupts computer after specified period to ensure
operating system maintains control.
Timer is decremented every clock tick.
When timer reaches the value 0, an interrupt occurs.
This is because we don’t want a user process to hold device
directly.
Timer commonly used to implement time sharing.