Implementations of core operating-system mechanisms in C against the POSIX API on Linux, with a Python simulator for contiguous memory allocation. Each module isolates one idea and is meant to be read, built, and run on its own.
The through-line is concurrency and correctness: how the kernel schedules work you cannot fully predict, and the primitives that keep shared state consistent in spite of it.
| # | Module | Demonstrates | Language |
|---|---|---|---|
| 01 | processes | fork, execl, waitpid, and scheduler-driven interleaving |
C |
| 02 | threads | POSIX threads over shared state, guarded by a pthread_mutex |
C |
| 03 | semaphores | bounded-buffer producer/consumer with counting and binary semaphores | C |
| 04 | bankers-algorithm | deadlock avoidance: safety check with grant, deny, and rollback | C |
| 05 | contiguous-memory | best-fit placement with compaction and a wait queue | Python |
Each module carries a NOTES.md explaining what the code does and what its output demonstrates.
The C modules need gcc; the concurrency modules link pthreads. Run each block from the repository root:
# 01 processes: build the main program and the two child images it exec's, then run
( cd 01-processes && gcc main.c -o main && gcc child1.c -o child1 && gcc child2.c -o child2 && ./main )
# 02 threads
( cd 02-threads && gcc ecommerce_threads.c -o ecommerce_threads -lpthread && ./ecommerce_threads )
# 03 semaphores (writes output.txt)
( cd 03-semaphores && gcc semaphores.c -o semaphores -lpthread && ./semaphores )
# 04 banker's algorithm (reads the request from stdin)
( cd 04-bankers-algorithm && gcc bankers.c -o bankers && ./bankers )
# 05 contiguous memory (Python 3)
( cd 05-contiguous-memory && python3 best_fit_sim.py ) # Tkinter GUI
( cd 05-contiguous-memory && python3 run_headless.py ) # no display requiredReleased under the MIT License. See LICENSE.