Introduction to Operating Systems (OS)
An Operating System (OS) is system software that acts as an intermediary between a computer user and the underlying computer hardware. The primary objective of an OS is to provide an environment in which a user can execute programs conveniently and efficiently.
Dual Role of an Operating System
An operating system performs two main fundamental functions:
-
User Interface / Extended Machine (Abstraction):
- Hides the complex details of physical hardware (e.g. disk read/write sectors, memory addresses, register states).
- Provides clean, easy-to-use abstractions such as files, directories, processes, and sockets.
-
Resource Manager:
- Manages system resources (CPU time, main memory, disk storage, I/O devices) among competing processes.
- Prevents conflicts and ensures fair, secure allocation of system resources.
Dual-Mode Operation & Hardware Protection
Modern computer architectures provide hardware support to distinguish between execution modes, ensuring user applications cannot crash the operating system or access unauthorized memory.
| Mode | Mode Bit Value | Privileged Instructions | Description |
|---|---|---|---|
| User Mode | 1 | Disallowed | Execution state for user application code. Direct access to hardware/memory is restricted. |
| Kernel / Supervisor Mode | 0 | Allowed | Execution state for OS kernel code. Full access to hardware, registers, and memory addresses. |
Mode Switching Mechanisms
- Trap / Software Interrupt: Executed when a user application requests an OS service via a system call. The CPU mode bit flips from
1(User) to0(Kernel), transfers control to an OS handler routine, executes the request, resets the mode bit to1, and returns to user space. - Hardware Interrupt: Triggered by external hardware devices (e.g. timer interrupts, keyboard presses, disk read completion).
System Calls
A System Call is a programmatic interface used by an executing application to request services directly from the operating system kernel.
Categories of System Calls
- Process Control:
fork(),exec(),exit(),wait(). - File Management:
open(),read(),write(),close(). - Device Management:
ioctl(),read(),write(). - Information Maintenance:
getpid(),time(),sleep(). - Communication & Networking:
pipe(),shmget(),socket(),bind(),connect().
Types of Operating Systems
1. Batch Operating System
- Jobs with similar requirements are batched together and executed sequentially without interactive user intervention.
- Drawback: CPU idle time remains high during I/O operations.
2. Multiprogramming OS
- Keeps multiple processes in main memory simultaneously.
- When the currently executing process waits for an I/O operation, the OS switches the CPU to another ready process.
- Objective: Maximize CPU utilization.
3. Time-Sharing / Multitasking OS
- An extension of multiprogramming where CPU time is divided into small time slices (quantums) using preemption (e.g. Round Robin scheduling).
- Objective: Provide interactive response time to multiple users.
4. Real-Time OS (RTOS)
- Designed for systems where execution must satisfy strict real-time constraints (e.g. aerospace, medical devices, automotive control).
- Hard Real-Time: Missing a deadline results in total system failure.
- Soft Real-Time: Missing a deadline degrades performance but is not catastrophic.
Goals of an Operating System
- Primary Goal: Convenience (User-friendliness and ease of program execution).
- Secondary Goal: Efficiency (Optimal utilization of CPU, memory, and storage resources).
Solved GATE Concept Questions
Question 1 (GATE CS)
Which of the following instructions must be privileged?
- Set value of timer
- Read the time-of-day clock
- Clear memory
- Turn off interrupts
Options:
- (A) 1, 2, and 3 only
- (B) 1, 3, and 4 only
- (C) 2 and 4 only
- (D) 1 and 4 only
Correct Answer: (B) 1, 3, and 4 only
Explanation:
- Modifying the timer, clearing memory assigned to other processes, and disabling hardware interrupts can halt system operation or bypass security. Therefore, these operations are privileged and can only be executed in Kernel Mode.
- Reading the time-of-day clock is a read-only, non-destructive operation and can be safely executed in User Mode.