Skip to main content

OS abstraction, extended machine, system call

Short answer

The OS abstracts hardware by providing files, processes, and virtual memory, hiding controller details. A system call allows user programs to request privileged services via a library function. For write(), the wrapper places the call number and executes TRAP; the kernel handler performs the I/O and returns.

How does an operating system create abstraction? Explain with reference to OS as an extended machine. Define system call and explain its working mechanism with a suitable example.

How an OS creates abstraction (OS as an extended machine)

Real hardware is complex: a disk is a controller with registers, sectors, cylinders, commands and interrupts. A programmer cannot be expected to handle this. The OS therefore builds a layer of abstraction above the hardware: it hides the details and exports simple, uniform and powerful objects.

  • Disk and storage become files and directories; a programmer opens, reads and writes a named file without caring about blocks.
  • CPU becomes processes/threads; each process appears to own a CPU.
  • Physical memory becomes an address space (virtual memory).
  • Network card becomes a socket; terminals/keyboard become simple character streams.

In this role the OS acts as an extended machine (virtual machine): it turns the ugly raw machine into a more convenient and better-looking machine, as seen from the application's point of view. Since the programmer sees only the abstractions, the program is also more portable among different hardware.

 Application  --> sees: files, processes, memory
 ----------------------------------------------
 OS (abstraction layer)
 ----------------------------------------------
 Hardware     --> disk controllers, registers, IRQs

System call and its working mechanism

A system call is the interface between a user program and the OS: it is a controlled entry point by which a user program asks the kernel to do a privileged operation (file I/O, process creation, memory allocation). Examples: open, read, write, fork, exec, exit.

Working (example: write(fd, buf, n) in C):

  1. The program calls the library wrapper write, passing parameters on the stack or in registers.
  2. The wrapper puts the system-call number in a register and executes a TRAP (software interrupt) instruction.
  3. The CPU switches from user mode to kernel mode and jumps to the kernel's system-call handler.
  4. The handler uses the call number to index the system-call table, validates the parameters, and runs the kernel routine (for write, it passes the data to the file system and device driver).
  5. After completion the kernel stores the return value, switches back to user mode and returns control to the instruction after the TRAP.

The mode switch protects the OS because user programs cannot execute privileged instructions directly; they must go through well-defined entries.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 1 questions →