CS401: Advanced Operating Systems - Assignment 1
This project presents an operating system simulator focused on robust process management. It provides a foundational understanding of how an OS handles various processes, their states, and resource allocation.
Key Features Include:
- Process Control Block (PCB) Management: Centralized control for process data.
- Flexible Scheduling: Support for multiple algorithms to manage process execution.
- Dynamic State Transitions: Processes move seamlessly through NEW, READY, RUN, BLOCKED, and TERMINATED states.
- Instruction Execution Simulation: Simulates CPU instruction processing.
- Time-Slice Preemption: Fair resource allocation through time-based interruptions.
The project is organized into logical units for clarity and maintainability:
.
├── ScisSos.h # Header file: Data structures & function declarations
├── process.c # Process management: create, run, delete processes
├── simulator.c # OS core: initialization, scheduler, queue operations
├── scheduler_fcfs.c # FCFS (First Come First Served) scheduling algorithm
├── scheduler_priority.c # Priority-based scheduling algorithm
├── scheduler_sjf.c # SJF (Shortest Job First) scheduling algorithm
├── main.c # Main simulator program entry point
└── Makefile # Build automation and configuration
Easily compile the simulator using the provided Makefile.
make allmake os_sim_fcfs
make os_sim_priority
make os_sim_sjfRun the compiled simulators to observe different scheduling behaviors.
./os_sim_fcfs # First Come First Served
./os_sim_priority # Priority Scheduling
./os_sim_sjf # Shortest Job Firstmake run_fcfs
make run_priority
make run_sjf
make run_all # Runs all three sequentiallyRemove compiled binaries and object files:
make cleanProcessInstruction: Defines instruction types (syscall) and memory addresses.PCB: The heart of process management, holding complete state information.Process: Encapsulates process metadata, PCB, and executable code.Queues: Efficient management of ready and blocked processes.
- Dynamic Creation: Processes are created with random instruction sets, mimicking real-world variability.
- Execution & Counting: Simulated instruction execution, allowing for performance analysis.
- Automatic State Transitions: Processes automatically transition between states based on events.
- Time-Slice Preemption: Ensures fair CPU time distribution (default: 5 instructions per slice).
- Pluggable Design: Easily integrate new scheduling algorithms.
- Three Implementations: FCFS, Priority, and SJF are provided.
- Blocked Process Handling: The scheduler intelligently manages processes waiting for resources.
SHORT_SYSCALL (0): Represents normal, non-blocking instructions.LONG_SYSCALL (1): Simulates I/O operations or events that cause a process to block.
- OS Initialization: The simulator environment is set up.
- Process Creation: 10 processes are generated with random properties (instructions, priority).
- Ready Queue Population: All newly created processes are added to the ready queue.
- Scheduler Activation: The scheduler selects a process based on the chosen algorithm.
- Process Execution: The selected process executes instructions until:
- A
LONG_SYSCALLis encountered (process blocks). - Its allocated time slice expires (process preempts).
- All instructions are completed (process terminates).
- A
- Scheduler Invocation: Upon any of the above events, the process yields control back to the scheduler.
- Loop Continuation: Steps 4-6 repeat until no processes remain in the system.
- Single-Threaded: The simulation runs in a single thread, simplifying concurrency management for this assignment.
- Process Limit: Supports a maximum of 100 processes.
- Default Time Slice: Processes are preempted after executing 5 instructions.
- Random Instruction Counts: Processes have instruction counts ranging from 10 to 30.
- Random Priority: Priority values are randomly assigned between 0 and 9.
- Blocked Probability:
LONG_SYSCALL(blocking events) occur with approximately 20% probability. - Random Unblocking: Blocked processes can randomly become unblocked within the scheduler logic.