Linux-like Operating System

KOS: a small Unix-like OS in C for a MIPS-like architecture with process/memory management, FIFO scheduling, and a Unix-style syscall interface.

About This Project

This project is a small, Unix-like operating system (OS) written in C. It's a great example of how an OS manages multiple programs, memory, and talks to the computer's hardware.

Project Overview

This project is a custom-built operating system designed to run on a MIPS-like architecture. The primary goal was to learn a deep understanding of fundamental OS concepts by implementing them from scratch. This includes process and memory management, scheduling, and a system call interface that allows user programs to interact with the kernel.

Key Features

  • Process Management: The OS can create new processes using a fork() system call, which makes an exact copy of the parent process. It can also load and run new programs using execve(). Processes are managed using Process Control Blocks (PCBs) that store essential information like register values, process ID, and memory allocation.
  • Memory Management: KOS uses a simple memory management scheme, dividing the available memory into fixed-size partitions. When a new process is created, it's allocated a free memory block. The sbrk() system call is implemented to allow processes to dynamically request more memory.
  • Scheduling: A basic, non-preemptive First-In, First-Out (FIFO) scheduler is used. Processes that are ready to run are placed in a ready queue, and the scheduler picks the one at the front of the queue to run next.
  • System Calls: A comprehensive set of Unix-like system calls are implemented to provide an interface between user programs and the kernel, including:
    • read() and write() for I/O operations.
    • fork(), execve(), exit(), and wait() for process control.
    • pipe() for inter-process communication.
    • dup() and dup2() for file descriptor manipulation.
    • getpid() and getppid() to get process and parent process IDs.
  • Inter-process Communication (IPC): The pipe() system call allows for one-way communication between processes. This is a powerful feature that enables complex interactions between different programs.

Technical Details

  • Language: C
  • Core Data Structures:
    • Process Control Block (PCB): A struct in C is used to store all the information about a process.
    • Ready Queue: A doubly-linked list (Dllist) is used for the ready queue.
    • Process and File Descriptor Tables: Red-black trees (JRB) are used to efficiently manage processes and file descriptors.
    • Concurrency: Semaphores are used to handle synchronization and prevent race conditions, especially for console I/O and pipe operations.

Learning Outcomes

  • The inner workings of an operating system.
  • Low-level systems programming in C.
  • Understanding when and how to implement complex data structures and algorithms.
  • Concurrency control and synchronization using semaphores.
  • The challenges of debugging kernel-level code.

This project solidified my understanding of operating systems and gave me an appreciation for the complexity and elegance of OS design.

Technologies Used

CPCBsFIFO schedulerSystem calls (fork/execve/pipe/dup2)IPCSemaphoresRed-black treesDllist (ready queue)