Past exam question: 2078 (Past Questions), QB
Open in the Padhaiko appExplain how operating system creates abstraction to the user? Explain with an example of system call and its working mechanism. Define multi-programming OS and real time OS.
Solution
How the Operating System Creates Abstraction (Extended Machine View): Raw computer hardware consists of intricate, low-level physical components: memory chips, bus controllers, CPU registers, and storage platters with tracks and sectors. Writing software directly against bare hardware would require managing disk motor timings, cylinder seek commands, DMA channels, and interrupt vectors manually.
The operating system bridges this gap by acting as an extended machine, transforming primitive hardware mechanisms into clean, high-level abstractions:
- Storage Abstraction: The OS hides physical disk sectors, heads, and bad blocks behind the concept of files and hierarchical directories. Applications interact with intuitive operations (
open,read,write) instead of sending raw ATA/NVMe commands. - Processor Abstraction: Physical CPU cores and execution pipelines are abstracted into processes and threads, providing each application with the illusion of an isolated, continuous instruction stream.
- Memory Abstraction: Disjoint physical RAM frames, page tables, and disk swap areas are abstracted into a uniform, private virtual address space for each process.
- I/O Abstraction: Diverse communication peripherals (Ethernet, Wi-Fi, serial ports) are unified behind standardized character/block device interfaces and network sockets.
System Call Example and Detailed Working Mechanism: Consider the standard POSIX system call ssize_t read(int fd, void *buf, size_t count);, which reads up to count bytes from file descriptor fd into buffer buf:
- Parameter Setup: The user-level C program invokes
read(). The C runtime library wrapper places arguments into dedicated CPU registers according to the platform calling convention (on x86-64:rdi = fd,rsi = buf,rdx = count, and system call number intorax). - Trap Instruction / Privilege Escalation: The wrapper executes a software trap/interrupt instruction (e.g.,
syscallon x86-64 orint 0x80on 32-bit x86). The CPU hardware atomically saves the current program counter and flags, switches privilege from User Mode (Ring 3) to Kernel Mode (Ring 0), and jumps to the kernel's system call entry point defined in the Interrupt Descriptor Table (IDT). - Dispatching via System Call Table: The kernel system call handler indexes into an internal dispatch table (
sys_call_table) using the number stored inraxto locatesys_read(). - Validation and Kernel Execution: The kernel validates pointer addresses, verifies read permissions on
fd, invokes the appropriate file system or device driver routine to fetch data, and transfers data into the user-space bufferbuf. - Return and Mode Restoration: The kernel stores the result (number of bytes read or an error code such as
-EFAULT) inrax, restores saved user registers, and executessysret(oriret). The CPU privilege drops back to Ring 3, resuming the application immediately following the call.
Definitions of Multi-programming OS and Real-Time OS:
- Multi-programming Operating System: An operating system that keeps multiple jobs/processes in main memory simultaneously. Whenever the currently running process becomes idle waiting for an external event (such as disk I/O, user input, or network data), the OS context-switches the CPU to another runnable process. The primary objective is to maximize CPU utilization by overlapping compute and I/O cycles.
- Real-Time Operating System (RTOS): An operating system specifically designed for applications where processing must be completed within strictly defined, deterministic time constraints called deadlines. System correctness depends not only on producing logically accurate results, but also on delivering those results before the deadline expires. RTOS systems are divided into Hard Real-Time (missing a deadline results in total system failure or catastrophic damage, e.g., avionics, automotive airbag deployment) and Soft Real-Time (missing a deadline degrades quality of service but does not cause catastrophic failure, e.g., video streaming, audio playback).
The OS creates abstraction by converting low-level physical hardware components into high-level models such as files, virtual memory, and processes. A system call (e.g., read) operates via register parameter staging, CPU trap execution for atomic user-to-kernel mode escalation, syscall table indexing, kernel execution, and privilege demotion back to user mode. A multiprogramming OS maintains multiple active processes in memory to keep the CPU busy during I/O waits, whereas a real-time OS guarantees deterministic execution completed within strict deadlines.