Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧰 System Resource Monitor & Process Scheduler Simulator

C C++ Bash

🔬 Real-time OS Simulation • Multi-threaded C/C++ • IPC • Shell Automation


🧩 Project Overview

This project demonstrates core Operating Systems concepts through two practical modules:

  • A real-time, multi-threaded Resource Monitor in C that reads Linux /proc data, logs metrics, and publishes summaries via POSIX message queues.
  • A Process Scheduler Simulator in C++ implementing classic algorithms with metrics and Gantt chart output.

It’s ideal for students and practitioners who want a hands-on understanding of threading, synchronization, IPC, and CPU scheduling.


⚙️ Features

  • ✅ C-based Resource Monitor

    • CPU, Memory, Disk I/O, and Network monitoring (via /proc)
    • Multi-threaded producers + synchronized logger (producer–consumer pattern)
    • Alerts when CPU/MEM exceed thresholds
    • Periodic summaries via POSIX message queues (IPC)
    • Graceful shutdown (Ctrl+C)
  • ✅ C++ Scheduler Simulator (STL-based)

    • Algorithms: FCFS, SJF, Round Robin (q=2), Priority, Multilevel Queue
    • Computes Waiting Time, Turnaround Time, Throughput
    • Prints Gantt chart slices for visualization
    • Appends results to data/reports/scheduler_report.txt
  • ✅ IPC Consumer

    • Reads and prints live summaries from the POSIX message queue
  • ✅ Automation Scripts

    • cleanup_logs.sh — cleanup and retention for logs
    • health_check.sh — simple CPU/MEM threshold alerting
    • generate_report.sh — collates recent logs and scheduler report

🧠 How It Works

  • Threaded Monitoring (C)

    • One thread each for CPU, Memory, Disk, Network → enqueues metrics
    • Logger thread dequeues metrics, writes to data/logs/resource_log.txt, and raises alerts
    • Every few seconds, a summary (e.g., CPU=xx.x% MEM=yy.y%) is sent to a POSIX message queue (default: /sysmon_queue)
  • Scheduler Algorithms (C++)

    • Reads processes from CSV: PID,Arrival,Burst,Priority
    • Runs FCFS, SJF, RR(q=2), Priority, Multilevel Queue
    • Produces per-process waiting/turnaround, averages, throughput, and Gantt chart slices
  • IPC Messaging

    • Separate consumer reads summaries from the message queue and prints them to stdout

🖥️ System Requirements

  • Linux or Windows Subsystem for Linux (WSL)
  • GCC, G++, Make, Bash
  • Access to Linux /proc filesystem and POSIX message queues

Note: On Windows, use WSL and run commands from a WSL terminal.


🏗️ Installation & Setup

Clone the repository and build all targets:

git clone https://github.com/<your-username>/SystemResourceMonitor.git
cd SystemResourceMonitor
make all

If using WSL and your project is in a Windows folder, use:

cd "/path/to/SystemResourceMonitor"
make all

If needed, install build tools (Ubuntu): sudo apt update && sudo apt install -y build-essential


▶️ How to Run

🚦 Quick Start: All-in-One
make all && make run_monitor

Builds everything and starts the resource monitor. Press Ctrl+C to stop.

Resource Monitor started. Press Ctrl+C to stop.
Logging to data/logs/resource_log.txt
Sending summaries to POSIX mq /sysmon_queue (if available)

🖥️ Resource Monitor (C)
make run_monitor

Monitors CPU, memory, disk, and network. Logs to data/logs/resource_log.txt.

1697654321000,CPU,42.35
1697654321500,MEM,61.20
1697654322000,DISK,128,64
1697654322500,NET,4096,2048
1697654323000,ALERT,CPU_HIGH,91.75

📡 IPC Consumer (POSIX MQ)
./bin/ipc_consumer

Shows live summaries from the message queue.

[Summary] CPU=37.4% MEM=58.2%
[Summary] CPU=41.9% MEM=60.1%

📊 Scheduler Simulator (C++)
./bin/scheduler data/processes.csv

Runs all algorithms and prints Gantt chart. Appends to data/reports/scheduler_report.txt.

Algorithm: FCFS
PID	Waiting	Turnaround
1	0	5
2	4	6
3	7	15
Avg Waiting: 3.7, Avg Turnaround: 8.7, Throughput: 0.3
Gantt: |P1(0-5)|P2(5-8)|P3(8-16)| end=16

📝 Generate a consolidated report
bash scripts/generate_report.sh

The combined report is saved to data/reports/final_summary.txt.

=== System Resource Monitor Summary ===
... (last 50 log lines) ...

=== Scheduler Latest Report ===
... (last 50 scheduler report lines) ...

🕹️ (Optional) Interactive Menu
./bin/menu

Text-based menu to run all modules and scripts.


📂 Project Structure

SystemResourceMonitor/
├── src/
│   ├── resource_monitor.c         # C monitor (threads, /proc, IPC, signals)
│   ├── ipc_consumer.c             # POSIX mqueue summaries reader
│   ├── scheduler_simulator.cpp    # C++ scheduling simulator
│   └── main.cpp                   # minimal interactive menu
├── include/
│   ├── monitor.h
│   └── scheduler.h
├── scripts/
│   ├── cleanup_logs.sh
│   ├── health_check.sh
│   └── generate_report.sh
├── data/
│   ├── processes.csv              # sample scheduler input
│   ├── logs/
│   │   └── resource_log.txt       # generated at runtime
│   └── reports/
│       └── scheduler_report.txt   # generated at runtime
├── bin/                           # built executables
├── Makefile
└── README.md

🧪 Sample Output

  • Gantt chart (console):
Algorithm: FCFS
PID	Waiting	Turnaround
1	0	5
2	4	6
3	7	15
Avg Waiting: 3.7, Avg Turnaround: 8.7, Throughput: 0.3
Gantt: |P1(0-5)|P2(5-8)|P3(8-16)| end=16
  • Resource log snippet (data/logs/resource_log.txt):
1697654321000,CPU,42.35
1697654321500,MEM,61.20
1697654322000,DISK,128,64
1697654322500,NET,4096,2048
1697654323000,ALERT,CPU_HIGH,91.75
  • IPC consumer (summaries):
[Summary] CPU=37.4% MEM=58.2%
[Summary] CPU=41.9% MEM=60.1%

🚀 Future Enhancements

  • Shared Memory or Pipes as an additional IPC demo
  • Cron integration for health_check.sh
  • Live statistics in the interactive menu (e.g., stream last summary)
  • Configurable thresholds and sampling intervals via a config file

🤝 Contributing

Contributions are welcome! Feel free to open issues or submit PRs:

  • Add new scheduling algorithms or visualizations
  • Improve error handling, parsing, or portability
  • Expand documentation and examples

Please follow conventional commit messages and include a brief description of changes.


📜 License

This project is licensed under the MIT License – see the LICENSE file for details.


✨ Credits / Authors

  • Maulishka Srivastava @Maulishka04
  • Thanks to the Linux /proc documentation and the C/C++ standard libraries

About

System Resource Monitor & Scheduler Simulator Project

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages