[Day 7] 1. Dual Mode Operation of OS
Differentiating OS Processes and User Processes
- User processes are the regular programs you run as a user, like opening a text editor or a browser. These are run in user mode, which has limited access to system resources.
- OS processes are executed when the system itself needs to perform tasks. These run in kernel mode, which has full access to hardware and system resources. Kernel mode is triggered when a system call is made (for example, when your program requests access to a file or device).
Interrupt Handling
An interrupt is a signal to the CPU that some event needs immediate attention. Interrupts stop the current execution and allow the CPU to deal with the event.
Steps in Interrupt Handling:
- Save execution context: The current state of the process (including register values) is saved so it can be resumed later.
- Identify the Interrupt Service Routine (ISR): The CPU looks up the correct ISR based on the interrupt’s number. Each interrupt has a unique identifier, and the addresses of ISRs are stored in the Interrupt Vector Table (IVT).
- Call the ISR function: The ISR handles the interrupt.
- Restore execution context: After handling the interrupt, the CPU resumes the paused process.
Dual Mode Operation
Operating systems operate in two modes:
- User mode: Here, the system restricts access to critical hardware. Some CPU registers and instructions, especially those related to input-output (I/O), are off-limits to user programs.
- Kernel mode: All CPU instructions and hardware resources are accessible. Whenever a system call or interrupt occurs, the CPU switches to kernel mode to execute privileged instructions.
!1. Dual.png
System Call API Layer:
A system call allows user processes to request services from the operating system. For example, when you use a function like
fopen()open()- User mode: The library function (like ) runs here.
fopen() - Kernel mode: The system call itself (like ) runs in kernel mode, which involves generating a software interrupt to switch to privileged mode.
open()
Software Interrupt (SWI) Handling
When a software interrupt occurs, similar steps are taken as in hardware interrupts:
- The current process's context is saved.
- The address of the actual system call implementation is found.
- The system call is executed.
- The CPU resumes the interrupted process after the system call completes.
System Call Table
The system call table holds the addresses of system call functions. When a software interrupt occurs, the CPU looks up the correct function from this table to handle the request.
Interrupt Priority
When multiple interrupts occur, the Interrupt Controller prioritises them and sends the highest priority interrupt to the CPU first. This ensures that more urgent tasks are handled without delay.
Read Next
[Day 7] 2. Hard Link and Symbolic Link
### **Hard Link** A **hard link** is essentially another name for the same file. It doesn’t create a new file; instead, it creates an additional di...
[Day 7] 3. Back to Shell Scripting
### **Positional Parameters** Positional parameters are arguments passed to a script from the command line when you execute it. They allow you to p...