This project demonstrates object-oriented programming concepts in C++, alongside reading system data from Linux files and displaying formatted outputs in a text-based interface, similar to the htop command-line tool.
- Project Overview
- Project Structure
- Dependencies
- Building and Running the Project
- Explanation of Files
- License
The goal of this project is to:
- Use Object-Oriented Programming (OOP) to structure code in C++.
- Collect and display system metrics (like CPU and memory usage) using data from the Linux
/procfile system. - Display the information in a text-based user interface using the ncurses library.
src/main.cpp: The entry point of the project. It initializes system data collection and starts the ncurses-based display.src/format.cppandinclude/format.h: Contains functions for formatting strings, particularly for time representation.src/ncurses_display.cppandinclude/ncurses_display.h: Handles the user interface using the ncurses library. It displays CPU, memory, and process information in the terminal.src/linux_parser.cppandinclude/linux_parser.h: Reads system and process data from the Linux file system, especially the/procdirectory.src/system.cppandinclude/system.h: Implements a class responsible for gathering and managing overall system data, like total processes, CPU utilization, and uptime.src/process.cppandinclude/process.h: Manages data and logic for individual processes, displaying metrics like CPU usage and memory consumption.src/processor.cppandinclude/processor.h: Contains logic specific to CPU data collection and processing.
To run this project, the following dependencies must be installed:
- Linux OS (Linux kernel >= 2.6)
- cmake >= 3.11.3
- make >= 4.1
- gcc/g++ >= 7.4.0
- ncurses (a library for terminal-based GUI):
- Install ncurses using the following command:
sudo apt install libncurses5-dev libncursesw5-dev
- Install ncurses using the following command:
-
Clone the repository:
git clone https://github.com/your-username/linux-system-monitor.git cd linux-system-monitor -
Create a
builddirectory and navigate into it:mkdir build cd build -
Build the project using
cmakeandmake:cmake .. make
-
Run the executable:
./monitor
- CMakeLists.txt: Defines the build configurations for the project.
cmakereads this file to generate makefiles for compiling the project. - src/format.cpp: Contains helper functions for formatting time and strings, making the output more readable.
- src/ncurses_display.cpp: Implements the display logic using the ncurses library to show real-time system data in the terminal.
- src/linux_parser.cpp: Reads raw system data from Linux's
/procfile system, providing details like CPU usage, memory, and process statistics. - src/system.cpp: Manages system-wide data like total processes, running processes, and CPU usage.
- src/process.cpp: Retrieves and manages data for individual processes, enabling detailed per-process information display.
- src/processor.cpp: Dedicated to CPU-related information, calculating real-time CPU utilization.
If you encounter a Segmentation Fault (core dumped) error, it is likely due to accessing invalid memory. Consider using gdb (GNU Debugger) to trace the error:
gdb ./monitor