This repository contains implementations for the core laboratory units of the "Operating Systems" course at ECE, NTUA. The projects cover process management, Inter-Process Communication (IPC), multithreaded programming, and synchronization mechanisms within a Unix environment.
This unit focuses on building a multi-process system to perform parallel text processing with a high degree of reliability.
- Frontend: The user interface utilizing
poll()for non-blocking I/O. - Dispatcher: The central coordinator that partitions data into chunks and manages worker lifecycles.
- Workers: Child processes (
fork) that execute the character counting logic.
- IPC: Communication is handled via anonymous Pipes.
- Fault Tolerance: The system is resilient to worker failures. If a worker is terminated (
SIGKILL), the Dispatcher detects the exit viaSIGCHLD, retrieves the incomplete task from thecurrent_tasktable, and reassigns it to a new worker. - Signals: Robust management of
SIGCHLDfor process monitoring,SIGINTfor graceful shutdowns &SIGTERMfor the smooth termination of the app.
This unit marks the transition from heavy processes to lightweight threads (pthreads) and shared memory.
A study of thread contention over a shared variable.
- Problem: Simultaneous modifications leading to "Lost Updates."
- Solution 1 (Mutexes): Software-level mutual exclusion using
pthread_mutex. - Solution 2 (Atomic Ops): Hardware-level synchronization using GCC atomic built-ins for lock-free performance.
Parallel computation of the Mandelbrot Set requiring strict sequential output.
- Problem: Multiple threads calculate image lines in parallel, but terminal output must remain ordered (Line 0, then Line 1, etc.).
- Semaphores: Implemented a "token-passing" logic using an array of semaphores.
- Condition Variables: Utilized an array of Condition Variables to signal specific threads, effectively avoiding the Thundering Herd problem.
Common utility functions (found in utils.{c,h}) used across all exercises to ensure system stability:
writes/reads: Wrapper functions (writesafe & readsafe )that handleEINTR(signal interruptions) and Partial Reads/Writes in pipes.
For LAB 1, across with other useful, safe and checking functions.
perror_pthread: A macro designed to map pthread return codes toerrnoso that standard error reporting can be used.
For LAB 2, across with other useful, safe and checking functions.