This is a side project I created based on the System Monitor Project in the Object Oriented Programming Course of the Udacity C++ Nanodegree Program.
Udacity provides a browser-based Linux Workspace for students.
You are welcome to develop this project on your local machine, and you are not required to use the Udacity Workspace. However, the Workspace provides a convenient and consistent Linux development environment we encourage you to try.
ncurses is a library that facilitates text-based graphical output in the terminal. This project relies on ncurses for display output.
Within the Udacity Workspace, .student_bashrc automatically installs ncurses every time you launch the Workspace.
If you are not using the Workspace, install ncurses within your own Linux environment: sudo apt install libncurses5-dev libncursesw5-dev
This project uses Make. The Makefile has the following targets:
allruns format, test, and buildformatapplies ClangFormat to style the source codebuildcompiles the source code and generates an executabledebugcompiles the source code and generates an executable, including debugging symbolstestcompiles and runs the testscleandeletes thebuild/directory, including all of the build artifacts
-
Clone the project repository:
git clone https://github.com/udacity/CppND-System-Monitor-Project-Updated.git -
Build the project:
make build -
Run the resulting executable:
./build/monitor
The following is an explanation of the program's data flow based on the provided structure and components:
-
main():-
The program starts from the
main()function. -
In
main(), the main objects are initialized:-
System: Manages all system information. -
NCursesDisplay: Displays system information on the command-line interface.
-
-
NCursesDisplay::Display()is called to start displaying information.
-
-
System:-
The
Systemclass is responsible for retrieving data from the system throughLinuxParser. -
Methods in
Systemcall the corresponding functions inLinuxParserto retrieve information:-
CPU:
LinuxParser::CpuUtilization()returns CPU utilization. -
Memory:
LinuxParser::MemoryUtilization()returns memory utilization. -
Uptime:
LinuxParser::UpTime()returns the system's uptime. -
Processes:
-
LinuxParser::Pids()returns a list of PIDs (Process IDs). -
LinuxParser::Command(),LinuxParser::Ram(),LinuxParser::User(), etc., return detailed information for each process.
-
-
**Operating System and Kernel`:
-
LinuxParser::OperatingSystem()returns the operating system name. -
LinuxParser::Kernel()returns the kernel version.
-
-
-
-
Processor:- The
Processorclass processes CPU-related information, such as calculating CPU utilization based on data fromLinuxParser.
- The
-
Process:-
Each process is represented by a
Processobject. -
Processretrieves detailed information for each process fromLinuxParser(such as PID, RAM, CPU utilization, uptime, etc.).
-
-
System:- The
Systemclass aggregates data fromProcessor, theProcesslist, and other information (memory, uptime, etc.).
- The
-
NCursesDisplay:-
The
NCursesDisplayclass is responsible for displaying data on the command-line interface. -
It consists of two main parts:
-
DisplaySystem():-
Displays general system information, such as:
-
Operating system name.
-
Kernel version.
-
CPU and memory utilization (as progress bars).
-
Total number of processes and number of running processes.
-
System uptime.
-
-
-
DisplayProcesses():-
Displays a list of processes, including:
-
PID.
-
Username.
-
CPU utilization.
-
RAM.
-
Uptime.
-
Command being executed.
-
-
-
-
NCursesDisplaycontinuously updates data fromSystemand displays information in real-time.
-
-
Data from the System:
LinuxParserreads data from system files in proc (e.g., stat, meminfo,/proc/[PID]/status, etc.).
-
Data Processing:
Systemand its child components (Processor,Process) process and store the data.
-
Data Display:
NCursesDisplayretrieves data fromSystemand displays it on the command-line interface.
-
LinuxParser:- Retrieves data from proc.
-
System:-
Calls
LinuxParserto retrieve data. -
Manages CPU (
Processor) and the process list (Process).
-
-
NCursesDisplay:-
Calls
Systemto retrieve data. -
Displays system and process information.
-
-
CPU Utilization:
-
NCursesDisplaycallsSystem::Cpu(). -
System::Cpu()returns aProcessorobject. -
ProcessorcallsLinuxParser::CpuUtilization()to retrieve data from stat. -
Processorcalculates CPU utilization and returns the result. -
NCursesDisplaydisplays CPU utilization as a progress bar.
-
-
Process List:
-
NCursesDisplaycallsSystem::Processes(). -
System::Processes()returns a list ofProcessobjects. -
Each
ProcesscallsLinuxParserto retrieve detailed information (PID, RAM, CPU, etc.). -
NCursesDisplaydisplays the process list.
-
The program's data flow is designed following a layered model:
-
LinuxParser: Retrieves data from the system. -
System: Manages and processes data. -
NCursesDisplay: Displays data on the command-line interface.
This organization makes the program easy to maintain, extend, and reuse.