This repository contains implementations of CPU scheduling algorithms in two forms:
- C++ CLI Application: Command-line scheduler with multiple algorithm implementations
- Electron Desktop Application: Interactive GUI built with React and TypeScript for visualizing scheduling algorithms
The project is designed for teaching, experiments, and demonstrations of various CPU scheduling algorithms including FCFS, SJF, SRTF, Round Robin, HRRN, and Multi-Level Feedback Queue.
Operating-System-Scheduling-Algorithms/
├── App/ # Electron desktop application
│ ├── src/
│ │ ├── main.ts # Electron main process
│ │ ├── preload.ts # Preload script for IPC
│ │ ├── renderer.tsx # React UI entry point
│ │ ├── algorithms/ # Algorithm implementations
│ │ └── components/ # React UI components
│ ├── public/
│ │ └── index.html # HTML template
│ ├── dist/ # Build output directory
│ ├── package.json # Node.js dependencies
│ ├── tsconfig.json # TypeScript configuration
│ └── webpack.config.js # Webpack build configuration
├── testcases/ # Example input files for testing
├── main.cpp # CLI driver for C++ scheduler
├── scheduler.h # Scheduler function declarations
├── process.h # Process structure definition
├── util.h # Utility function declarations
├── util.cpp # Input/output utilities
├── fcfs.cpp # FCFS algorithm implementation
├── sjf.cpp # SJF algorithm implementation
├── srt.cpp # SRTF algorithm implementation
├── rr.cpp # Round Robin implementation
├── hrrn.cpp # HRRN algorithm implementation
├── feedback.cpp # MLFQ implementation
├── Makefile # Build configuration for C++ code
└── Dockerfile # Container setup for reproducible builds
- FCFS (First-Come, First-Served): Non-preemptive scheduling based on arrival order
- SJF (Shortest Job First): Non-preemptive scheduling selecting shortest burst time
- SRTF (Shortest Remaining Time First): Preemptive version of SJF
- Round Robin: Time-sliced preemptive scheduling with configurable quantum
- HRRN (Highest Response Ratio Next): Non-preemptive scheduling optimizing response ratio
- Multi-Level Feedback Queue: Multi-level queue with priority aging
All algorithms from the C++ CLI, plus:
- Interactive process input
- Real-time Gantt chart visualization
- Results table with calculated metrics (completion time, turnaround time, waiting time)
- C++ compiler with C++17 support (g++, clang++)
- make
- Optional: Docker for containerized builds
- Node.js (LTS version 18+)
- npm (comes with Node.js)
- Build the scheduler:
make- Run with a specific input file:
./scheduler testcases/test_short_jobs.txt- Run all testcases in batch mode:
./scheduler --all-tests- Run with interactive menu:
./scheduler input.txt- Clean build artifacts:
make clean- Build Docker image:
make docker-build- Run in container:
docker run -it scheduler:latest- Navigate to the App directory:
cd App- Install dependencies:
npm install- Build the application:
npm run build- Start the application:
npm startFor iterative development:
npm run devThe app opens with DevTools enabled for debugging.
- Select an Algorithm: Choose from the dropdown menu (FCFS, RR, HRRN, MLFQ, SJF, SRT)
- Add Processes:
- Enter Process ID (e.g., "P1")
- Enter Arrival Time (e.g., 0)
- Enter Burst Time (e.g., 5)
- Click "Add Process"
- Repeat to add more processes
- Run Algorithm: Click "Run Algorithm" to execute and view results
- View Results:
- Results table shows completion time, turnaround time, and waiting time
- Gantt chart displays visual timeline of process execution
The C++ CLI reads process data from text files with the following format:
# Lines starting with # are comments
# Format: ProcessID ArrivalTime BurstTime
1 0 5
2 1 3
3 2 2
Example testcases are provided in the testcases/ directory.
Test files are located in testcases/ and cover various scenarios:
test_short_jobs.txt: Testing SJF advantagestest_convoy.txt: Demonstrating convoy effect in FCFStest_rr_fairness.txt: Round Robin time-slicing behaviortest_preempt_advantage.txt: Benefits of preemptive schedulingtest_starvation_vs_hrrn.txt: HRRN preventing starvationtest_feedback_mixed.txt: Multi-level feedback queue behavior
Run all tests:
./scheduler --all-testsThe Electron app currently uses mocked algorithm results for UI development. To integrate actual C++ algorithms:
Option 1: Spawn the compiled C++ binary from the main process using child_process
Option 2: Create a Node.js native addon (N-API) for direct function calls
Option 3: Compile algorithms to WebAssembly
main.cpp: Entry point, command-line argument parsingscheduler.h/cpp files: Individual algorithm implementationsutil.cpp: Input parsing and output formattingprocess.h: Process data structure
main.ts: Electron main process, window management, IPC handlerspreload.ts: Secure bridge between renderer and main processrenderer.tsx: React application rootcomponents/: React components for UI sectionswebpack.config.js: Multi-compiler configuration for bundling
- Renderer calls
window.api.runAlgorithm(algorithm, processes) - Preload script forwards to main process via
ipcRenderer.invoke - Main process handles request in
ipcMain.handle('run-algorithm') - Result is returned to renderer via Promise
window.apiundefined: Ensuredist/preload.jsexists after build- Build issues: Make sure all dependencies are installed with
npm install - Node version warnings: Upgrade to Node 18+ for best compatibility
- Interactive mode requires user input via stdin
- Use batch mode (
--batchflag) for automated testing
The project includes:
Makefilefor automated C++ buildsDockerfilefor containerized builds- Test scripts for validation
- Consistent build environment setup
Potential improvements:
- Integrate C++ algorithms into Electron app main process
- Add automated tests for algorithm correctness
- Implement hot reload for React development
- Add export/save functionality for results
- Add historical results tracking
- Pin dependency versions for reproducibility
MIT
Contributions are welcome! Please feel free to submit issues or pull requests for:
- Bug fixes
- New algorithm implementations
- UI improvements
- Documentation enhancements
- Test coverage expansion