PadhaikoAll subjects

Past exam question: 2078 (Past Questions), QB

Operating System · 4 marks

Open in the Padhaiko app

Topic: Introduction

Question

Explain 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:

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:

  1. 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 into rax).
  2. Trap Instruction / Privilege Escalation: The wrapper executes a software trap/interrupt instruction (e.g., syscall on x86-64 or int 0x80 on 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).
  3. Dispatching via System Call Table: The kernel system call handler indexes into an internal dispatch table (sys_call_table) using the number stored in rax to locate sys_read().
  4. 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 buffer buf.
  5. Return and Mode Restoration: The kernel stores the result (number of bytes read or an error code such as -EFAULT) in rax, restores saved user registers, and executes sysret (or iret). The CPU privilege drops back to Ring 3, resuming the application immediately following the call.

Definitions of Multi-programming OS and Real-Time OS:

Answer:

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.

All past exam questions for Operating System