2 Operating System Structures

Operating Systems · Unit 2

Operating System Structures

Exam-focused notes for Operating System Structures (Operating Systems, BIT204): what the TU syllabus asks and how it has actually been tested, with 6 solved past questions from this unit.

Operating System Structures in short

The structure of an operating system shows how its parts are arranged and how they talk to each other. This chapter also explains the kernel, system calls and interrupts, which are the base of all OS work.

Operating System Structures: notes

Monolithic kernel structure

In a monolithic kernel, the whole OS runs as one large program in kernel mode. Process management, memory management, file systems and device drivers all live in the same address space. Any part can call any other part directly.

Advantages:

  • It is fast, because calls between parts are plain function calls.
  • The design is simple to start with.

Disadvantages:

  • A bug in one driver can crash the whole system.
  • It is hard to maintain and extend.
  • The kernel becomes very large.

Traditional Unix and Linux are monolithic. Linux reduces the problem with loadable modules.

Microkernel structure

A microkernel keeps only the most basic services in the kernel. These are low level memory management, process scheduling and inter-process communication (IPC). File systems, device drivers and networking run as normal user programs called servers.

Advantages:

  • It is easy to extend, because new services are added in user space.
  • It is more reliable. A failed driver does not crash the kernel.
  • It is more secure, as less code runs in kernel mode.

Disadvantage:

  • It is slower, because services talk through message passing, which costs time.
Monolithic kernelMicrokernel
All services run in kernel space.Only basic services run in kernel space.
Fast, because calls are direct.Slower, because of message passing.
One failure can crash the system.A failed server does not crash the kernel.
Hard to extend.Easy to extend.

What this unit covers

  • Monolithic kernel structure
  • Microkernel structure
  • Kernel definition and role
  • System call definition and objectives
  • System call process and mechanism
  • Interrupt definition and occurrence

System call definition and objectives

2082 · 5 marks

Define system call? What are its objectives? [5]

Show solved answer

System Call: Definition and Objectives

Definition

A system call is a programmatic way in which a computer program requests a service from the kernel of the operating system. It provides an interface between a user-level process and the operating system, allowing user programs to request OS services that require higher privilege levels (kernel mode) than the user mode in which normal programs run.

In simple terms, a system call is a controlled entry point into the kernel through which a running program can ask the OS to perform operations on its behalf.

Example: When a program wants to read a file, it issues a read() system call rather than directly accessing the hardware.


Objectives of System Calls

System calls serve the following key objectives:

1. Hardware Abstraction

System calls hide the complexity of hardware from user programs. Programmers do not need to know the details of hardware devices; they simply call standard system call interfaces.

2. Protection and Security

They ensure that user programs cannot directly access hardware or critical OS resources. The OS validates each request, preventing unauthorized or harmful operations.

3. Resource Management

System calls allow the OS to manage and allocate resources (CPU, memory, I/O devices, files) in a controlled and fair manner among multiple processes.

4. Mode Switching (User Mode to Kernel Mode)

System calls provide a safe and controlled mechanism to switch from user mode to kernel mode, so that privileged instructions can be executed only under OS supervision.

5. Process Control

They allow user programs to create, terminate, and manage processes and threads (e.g., fork(), exec(), exit()).

6. Inter-Process Communication (IPC)

System calls provide mechanisms for processes to communicate and synchronize with each other (e.g., pipes, message queues, shared memory).

7. File and I/O Operations

They provide a standard interface for file management and input/output operations such as open(), read(), write(), and close().


Summary Table

ObjectiveExample System Call
Process Controlfork(), exit(), wait()
File Managementopen(), read(), write()
Device Managementioctl(), read(), write()
Information Maintenancegetpid(), alarm()
Communication (IPC)pipe(), shmget()

In conclusion, system calls act as the bridge between user applications and the operating system kernel, ensuring security, abstraction, and controlled access to system resources.

Open this answer on its own page →

2080 · 5 marks

What is system call? Explain the system call process in detail. [5]

A system call is a programmatic way in which a user-level program requests a service from the operating system kernel. It provides an interface between a running process (user space) and the operating system (kernel space). System calls allow user programs to perform privileged operations such as...

Open this answer on its own page →

0 · 5 marks

Define system call. Explain operating system as a extended machine. [5]

--- A system call is a programmatic interface through which a user-level program requests a service from the operating system kernel. It provides a controlled entry point into the kernel, allowing user programs to perform privileged operations (such as file I/O, process creation, memory allocatio...

Open this answer on its own page →

Interrupt definition and occurrence

2082 · 5 marks

Define interrupt. Describe about device controller. [2+3]

--- An interrupt is a signal sent to the CPU by hardware or software indicating that an event needs immediate attention. When an interrupt occurs, the CPU suspends its current execution, saves its state, and transfers control to a special routine called the Interrupt Service Routine (ISR) or inte...

Open this answer on its own page →

System call process and mechanism

2079 · 10 marks

What is kernel? Explain the process of system call with suitable diagram.[10]

Show solved answer

Kernel and System Call Process

What is Kernel? [3 marks]

The kernel is the core component of an operating system that acts as a bridge between application programs and the computer hardware. It is the first program loaded into memory when the computer starts (after the bootloader) and remains in memory throughout the entire session.

Key Characteristics of the Kernel:

  • It runs in privileged mode (also called kernel mode or supervisor mode), which gives it unrestricted access to all hardware resources.
  • It manages system resources such as CPU, memory, I/O devices, and file systems.
  • It provides a protected environment so that user programs cannot directly access hardware.

Functions of the Kernel:

FunctionDescription
Process ManagementCreates, schedules, and terminates processes
Memory ManagementAllocates and deallocates memory to processes
Device ManagementControls hardware devices via device drivers
File System ManagementManages files and directories on storage
Inter-Process CommunicationAllows processes to communicate with each other
System Call InterfaceProvides an interface for user programs to request services

Types of Kernel:

  1. Monolithic Kernel - All OS services run in kernel space (e.g., Linux, Unix)
  2. Microkernel - Only essential services run in kernel space (e.g., Minix)
  3. Hybrid Kernel - Combination of monolithic and microkernel (e.g., Windows NT)

System Call [7 marks]

Definition:

A system call is a programmatic way in which a user-level program requests a service from the operating system kernel. It provides the interface between a running process (user mode) and the operating system.

System calls are the only legal entry points into the kernel. When a user program needs to perform a privileged operation (such as reading a file, creating a process, or allocating memory), it must do so through a system call.

Types of System Calls:

  1. Process Control - fork(), exit(), wait()
  2. File Management - open(), read(), write(), close()
  3. Device Management - ioctl(), read(), write()
  4. Information Maintenance - getpid(), alarm(), sleep()
  5. Communication - pipe(), shmget(), mmap()

Process of System Call (Step-by-Step):

USER SPACE                          KERNEL SPACE
-----------                         ------------

[User Program]
     |
     | 1. Calls library function
     v
[Library / API]
  e.g., printf()
     |
     | 2. Prepares parameters,
     |    places system call
     |    number in register
     v
[TRAP / INT instruction]
  (Software Interrupt)
     |
     |-------- MODE SWITCH -------->
                                   [Kernel Mode Activated]
                                          |
                                          | 3. Hardware saves
                                          |    CPU state (registers,
                                          |    PC, flags)
                                          v
                                   [Trap Handler / Interrupt
                                    Vector Table]
                                          |
                                          | 4. Identifies system
                                          |    call number
                                          v
                                   [System Call Dispatcher /
                                    System Call Table]
                                          |
                                          | 5. Calls appropriate
                                          |    kernel routine
                                          v
                                   [Kernel Service Routine]
                                    e.g., sys_write()
                                          |
                                          | 6. Executes the
                                          |    requested service
                                          |
                                          | 7. Places return value
                                          |    in register
                                          |
     <------- MODE SWITCH ----------      |
[Return to User Mode]              [Kernel Mode Ends]
     |
     | 8. Library function
     |    retrieves return value
     v
[User Program Continues]

Detailed Steps Explained:

Step 1: User Program Makes a Request

  • The user program calls a high-level library function (e.g., read() in C).
  • This library function is part of the API (Application Programming Interface).

Step 2: Prepare for System Call

  • The library function places the system call number into a specific CPU register (e.g., register EAX in x86).
  • Any arguments/parameters are placed in other registers or on the stack.

Step 3: Execute TRAP Instruction

  • The library executes a special instruction called TRAP or INT (software interrupt), e.g., INT 0x80 in Linux x86.
  • This causes a mode switch from user mode to kernel mode.
  • The CPU saves the current state (program counter, registers, flags) onto the kernel stack.

Step 4: Trap Handler Invoked

  • The hardware transfers control to a fixed memory address -- the trap handler (defined in the interrupt vector table).
  • The trap handler verifies the system call number.

Step 5: System Call Dispatcher

  • The dispatcher uses the system call number as an index into the system call table.
  • The system call table is an array of function pointers pointing to kernel service routines.

Step 6: Kernel Service Routine Executes

  • The appropriate kernel routine (e.g., sys_read()) executes with full hardware privileges.
  • It performs the requested operation (reads from disk, allocates memory, etc.).

Step 7: Return from Kernel

  • The return value (success/error code) is placed in a register.
  • The kernel executes a return-from-trap instruction (e.g., IRET).
  • The CPU restores the saved state and switches back to user mode.

Step 8: User Program Resumes

  • The library function retrieves the return value from the register.
  • Control returns to the user program, which continues execution.

Diagram Summary:

+------------------+        System Call        +------------------+
|                  |  -----------------------> |                  |
|   USER PROCESS     |                           |     KERNEL       |
|   (User Mode)    |  <----------------------- |   (Kernel Mode)  |
+------------------+       Return Value        +------------------+
         |                                              |
         | 1. call read()                               |
         v                                              |
+------------------+                                    |
|  Library / API   |  2. system call number -> register |
|  (libc wrapper)  |  3. TRAP / INT 0x80                |
+---------+--------+                                    |
          |                                             v
          |                          +---------------------------+
          +------------------------->|  4. Trap handler          |
                                     |  5. System call dispatcher|
                                     |     (system call table)   |
                                     |  6. sys_read() executes   |
                                     +-------------+-------------+
                                                   |
                                     7. IRET, restore state, back to user mode

Conclusion

The kernel is the core of the operating system: it always resides in memory, runs in privileged mode, and owns the hardware. A user program can never touch that hardware directly, so a system call is the controlled doorway between the two worlds. The library wrapper loads the call number and arguments, a TRAP instruction switches the CPU into kernel mode, the dispatcher looks the number up in the system call table, the kernel routine does the work with full privilege, and a return-from-trap puts the CPU back in user mode with the result in a register. This mode switch is what keeps one process from corrupting another or the operating system itself.

Open this answer on its own page →

Kernel definition and role

2078 · 5 marks

What is kernel? Differentiate between monolithic and microkernel structure. [5]

The kernel is the core component of an operating system that acts as a bridge between application software and computer hardware. It manages system resources such as CPU, memory, and I/O devices, and provides essential services to all other parts of the OS. The kernel runs in privileged mode (ker...

Open this answer on its own page →