Skip to content

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.

Notifications You must be signed in to change notification settings

Vnadh/OS-SIMULATOR-Process-Management

Repository files navigation

OS SIMULATOR - Process Management

CS401: Advanced Operating Systems - Assignment 1


🚀 Overview

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.

📂 File Structure

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

🛠️ Compilation

Easily compile the simulator using the provided Makefile.

Compile All Scheduling Algorithms:

make all

Compile Individual Versions:

make os_sim_fcfs
make os_sim_priority
make os_sim_sjf

🚀 Execution

Run the compiled simulators to observe different scheduling behaviors.

Run Individual Simulators:

./os_sim_fcfs       # First Come First Served
./os_sim_priority   # Priority Scheduling
./os_sim_sjf        # Shortest Job First

Or Use Makefile Targets:

make run_fcfs
make run_priority
make run_sjf
make run_all        # Runs all three sequentially

🧹 Cleanup

Remove compiled binaries and object files:

make clean

✨ Key Features & Design

1. Data Structures

  • ProcessInstruction: 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.

2. Process Management

  • 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).

3. Scheduling

  • 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.

4. System Calls

  • SHORT_SYSCALL (0): Represents normal, non-blocking instructions.
  • LONG_SYSCALL (1): Simulates I/O operations or events that cause a process to block.

📊 Simulation Flow

  1. OS Initialization: The simulator environment is set up.
  2. Process Creation: 10 processes are generated with random properties (instructions, priority).
  3. Ready Queue Population: All newly created processes are added to the ready queue.
  4. Scheduler Activation: The scheduler selects a process based on the chosen algorithm.
  5. Process Execution: The selected process executes instructions until:
    • A LONG_SYSCALL is encountered (process blocks).
    • Its allocated time slice expires (process preempts).
    • All instructions are completed (process terminates).
  6. Scheduler Invocation: Upon any of the above events, the process yields control back to the scheduler.
  7. Loop Continuation: Steps 4-6 repeat until no processes remain in the system.

📝 Implementation Notes

  • 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.

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published