LabHub

Blog

[OS Concepts] 01. What is an Operating System

한국어English日本語

What is an Operating System

An operating system (OS) is software that manages computer hardware and provides an execution environment for application programs. It acts as an intermediary between the user and the hardware.

Four Components of a Computer System

A computer system consists of four major components.

  1. Hardware: Provides basic resources such as CPU, memory, and I/O devices
  2. Operating System: Controls hardware and coordinates resources among application programs
  3. Application Programs: Word processors, compilers, web browsers, etc., that solve user problems
  4. Users: People, other machines, or other computers

Roles of the Operating System

An operating system can be defined from two perspectives.

In a more universal definition, the operating system is the one program running at all times on the computer, called the kernel.


Computer System Organization

Interrupts

An interrupt is a mechanism for hardware to notify the CPU that an event has occurred. When an I/O device completes an operation, it sends a signal to the CPU through an interrupt.

[Interrupt Handling Process]

1. I/O device completes operation
2. Device controller raises interrupt signal
         |
         v
3. CPU suspends current operation
4. Saves current state (PC, registers) to stack
         |
         v
5. Looks up ISR address through interrupt vector
6. Executes ISR (Interrupt Service Routine)
         |
         v
7. Restores saved state
8. Resumes interrupted operation

The types of interrupts are as follows.

// Interrupt vector table conceptual diagram
// Stores ISR addresses corresponding to each interrupt number

typedef void (*isr_handler_t)(void);

isr_handler_t interrupt_vector_table[256];

// Interrupt number 0: Division by zero exception
// Interrupt number 1: Debug exception
// Interrupt number 14: Page fault
// ...
// Interrupt numbers 32~255: User-defined (I/O devices, etc.)

void handle_interrupt(int interrupt_number) {
    // Find and execute handler from interrupt vector
    isr_handler_t handler = interrupt_vector_table[interrupt_number];
    if (handler != NULL) {
        handler();
    }
}

Storage Device Hierarchy

Storage devices form a hierarchy based on speed, cost, and volatility.

[Storage Device Hierarchy]

      Fast / Expensive / Small
        +-----------+
        | Registers  |    < 1ns
        +-----------+
        | Cache (L1) |    ~1ns
        +-----------+
        | Cache (L2) |    ~4ns
        +-----------+
        | Cache (L3) |    ~10ns
        +-----------+
        | Main Memory|    ~100ns     (Volatile)
        +-----------+
        |   SSD     |    ~100us     (Non-volatile)
        +-----------+
        |   HDD     |    ~10ms
        +-----------+
      Slow / Cheap / Large

Caching is a technique that temporarily copies data from slower storage to faster storage. When the same data is accessed again, it is read from the faster storage, improving performance.

I/O Structure

I/O operations are performed through interactions between the CPU and device controllers.

[DMA Operation Process]

CPU                     DMA Controller          Memory
 |                           |                   |
 |-- DMA transfer request -->|                   |
 |   (source, dest, size)    |                   |
 |                           |--- Data transfer ->|
 |                           |--- Data transfer ->|
 |                           |--- Data transfer ->|
 |<-- Transfer complete int -|                   |
 |                           |                   |

Computer System Architecture

Multiprocessor Systems

Most modern computers are multiprocessor systems. The advantages are as follows.

  1. Increased Throughput: N processors improve processing speed (but not by N times)
  2. Economy of Scale: More cost-effective than multiple single-processor systems
  3. Increased Reliability: If one fails, the overall system continues to operate (graceful degradation)

There are two types of multiprocessor systems.

[SMP Architecture]

  CPU 0        CPU 1        CPU 2
 [Registers]  [Registers]  [Registers]
 [Cache]      [Cache]      [Cache]
    |             |             |
    +------+------+------+------+
           |             |
      [Shared Memory]  [I/O System]

Multicore Systems

A multicore processor contains multiple cores on a single chip. Since they communicate within the same chip, it is faster than communication between separate processors and consumes less power.

[Multicore Processor Structure]

+--------------------------------------+
|           Single CPU Chip            |
|  +--------+  +--------+  +--------+ |
|  | Core 0  |  | Core 1  |  | Core 2  | |
|  |[L1Cache]|  |[L1Cache]|  |[L1Cache]| |
|  +--------+  +--------+  +--------+ |
|         +----------+                  |
|         | L2 Cache  |                  |
|         +----------+                  |
+--------------------------------------+
              |
         [Main Memory]

NUMA (Non-Uniform Memory Access)

When the number of CPUs increases, the system bus becomes a bottleneck. NUMA solves this problem by providing each CPU with its own local memory.

[NUMA Architecture]

+------------------+    Interconnect    +------------------+
|     Node 0       |<================>|     Node 1       |
| CPU 0  CPU 1    |                   | CPU 2  CPU 3    |
| [Local Memory 0] |                   | [Local Memory 1] |
+------------------+                   +------------------+

Local memory access: Fast (~100ns)
Remote memory access: Slow (~300ns)

Operating System Operations

Dual-Mode Operation

The OS must protect the system from erroneous user program behavior. To this end, it provides two execution modes.

[Mode Transition Process]

User Mode                            Kernel Mode
    |                                   |
    |-- System call invocation -------->|
    |   (trap occurs, mode bit 0)       |
    |                                   |-- System call processing
    |                                   |
    |<-- System call return ------------|
    |   (mode bit restored to 1)        |
    |                                   |
// System call example: File read
// Calling read() from a user program

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>

int main() {
    char buffer[1024];

    // open() transitions to kernel mode via system call
    int fd = open("data.txt", O_RDONLY);

    // read() is also a system call - kernel performs I/O
    ssize_t bytes = read(fd, buffer, sizeof(buffer));

    printf("Bytes read: %zd\n", bytes);
    close(fd);
    return 0;
}

Timer

A timer prevents a program from monopolizing the CPU. After a set period, it generates an interrupt to return control to the OS.


Resource Management

Process Management

A process is a program in execution. The OS performs the following tasks.

Memory Management

Main memory is the only large storage directly accessible by the CPU. The OS manages the following.

Storage Management

The OS abstracts the physical characteristics of storage devices to provide the logical concept of files.

I/O Subsystem

The OS I/O subsystem hides the differences between hardware devices.


Protection and Security

Each user is assigned a unique ID (UID), and group-level access control is also possible through group IDs (GID). Privilege escalation is a mechanism for temporarily gaining higher privileges, implemented in Unix through the setuid bit.


Summary

[Operating System Key Concepts Summary]

+------------------------------------------+
|          Application Programs             |
+------------------------------------------+
|       Operating System (Kernel)           |
|  +------+ +--------+ +--------+ +------+ |
|  |Process| |Memory  | |File    | |I/O   | |
|  |Mgmt   | |Mgmt    | |System  | |Mgmt  | |
|  +------+ +--------+ +--------+ +------+ |
+------------------------------------------+
|              Hardware                     |
|  CPU / Memory / Disk / I/O Devices       |
+------------------------------------------+

The operating system is essential software that manages resources between hardware and users, provides a program execution environment, and protects the system. It leverages hardware support such as dual-mode operation, interrupts, and timers to ensure safe and efficient system operation.

Comments

No comments yet.

Sign in to leave a comment