Code used in class
This folder holds the code examples, demonstrations and simulators used in lectures and labs. Many come from the textbook’s ostep-code and ostep-homework repositories. Browse the files on GitHub.
Contents
Processes
- Process API:
fork_demo_*.c,exec_demo_*.c,wait_demo_*.c - Process creation:
p1.c,p2.c,p3.c,p4.c - Hello world programs:
hello.c,hello_world.c,hello_assembly.c
CPU scheduling
- Scheduling simulator:
scheduler.py,cpu-virtual.py - MLFQ:
mlfq.py - Lottery scheduling:
cpu-sched-lottery/lottery.c
Memory
- Memory examples:
mem.c,mem2.c,mem3.c - Address translation:
memory-address.c - Virtual memory:
vm-intro/va.c - Memory simulation:
relocation.py
Threads and concurrency
- Thread examples:
hello_thread.c,sum_thread.c - Thread API:
threads-intro/ - Synchronisation: code in the lab folders
I/O and system calls
- I/O examples:
io.c - System call tracing:
trace-io.*
Python simulators
- CPU scheduling:
scheduler.py - Memory management:
relocation.py,x86.py - Process execution:
process-run.py
Assembly
- Assembly code:
hello_world.s,loop.s,simple-race.s - Threading:
looping-race-nolock.s
How to use
- Compilation: Most C programs can be compiled with
gcc filename.c -o filename - Python scripts: Run with
python3 script.py - Makefiles: Use
makein directories that contain Makefiles - Threading: Compile with
-pthreadflag for threading examples
Common headers
common.h: Shared definitions and includescommon_threads.h: Threading-specific includes
Subfolders
Subfolders from the textbook’s code: - intro/: Introduction examples - cpu-api/: Process API exercises - threads-intro/: Threading introduction - vm-intro/: Virtual memory introduction