├── .clang-format ├── .github └── workflows │ └── manual.yml ├── .gitignore ├── CMakeLists.txt ├── CODEOWNERS ├── LICENSE ├── Makefile ├── README.md ├── images ├── monitor.png └── starting_monitor.png ├── include ├── format.h ├── linux_parser.h ├── ncurses_display.h ├── process.h ├── processor.h └── system.h └── src ├── format.cpp ├── linux_parser.cpp ├── main.cpp ├── ncurses_display.cpp ├── process.cpp ├── processor.cpp └── system.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Google 4 | -------------------------------------------------------------------------------- /.github/workflows/manual.yml: -------------------------------------------------------------------------------- 1 | # Workflow to ensure whenever a Github PR is submitted, 2 | # a JIRA ticket gets created automatically. 3 | name: Manual Workflow 4 | 5 | # Controls when the action will run. 6 | on: 7 | # Triggers the workflow on pull request events but only for the master branch 8 | pull_request_target: 9 | types: [assigned, opened, reopened] 10 | 11 | # Allows you to run this workflow manually from the Actions tab 12 | workflow_dispatch: 13 | 14 | jobs: 15 | test-transition-issue: 16 | name: Convert Github Issue to Jira Issue 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@master 21 | 22 | - name: Login 23 | uses: atlassian/gajira-login@master 24 | env: 25 | JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} 26 | JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} 27 | JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} 28 | 29 | - name: Create NEW JIRA ticket 30 | id: create 31 | uses: atlassian/gajira-create@master 32 | with: 33 | project: CONUPDATE 34 | issuetype: Task 35 | summary: | 36 | Github PR - nd213 C++ Nanodegree | Repo: CppND-System-Monitor | PR# ${{github.event.number}} 37 | description: | 38 | Repo link: https://github.com/${{ github.repository }} 39 | PR no. ${{ github.event.pull_request.number }} 40 | PR title: ${{ github.event.pull_request.title }} 41 | PR description: ${{ github.event.pull_request.description }} 42 | In addition, please resolve other issues, if any. 43 | fields: '{"components": [{"name":"nd213 C++"}], "customfield_16449":"https://classroom.udacity.com/nanodegrees/nd213/dashboard/overview", "customfield_16450":"Resolve the PR", "labels": ["github"], "priority":{"id": "4"}}' 44 | 45 | - name: Log created issue 46 | run: echo "Issue ${{ steps.create.outputs.issue }} was created" 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | monitor 2 | a.out 3 | settings.json 4 | *.o 5 | build/* 6 | *.json 7 | .github/** 8 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(monitor) 3 | 4 | find_package(Curses REQUIRED) 5 | include_directories(${CURSES_INCLUDE_DIRS}) 6 | 7 | include_directories(include) 8 | file(GLOB SOURCES "src/*.cpp") 9 | 10 | add_executable(monitor ${SOURCES}) 11 | 12 | set_property(TARGET monitor PROPERTY CXX_STANDARD 17) 13 | target_link_libraries(monitor ${CURSES_LIBRARIES}) 14 | # TODO: Run -Werror in CI. 15 | target_compile_options(monitor PRIVATE -Wall -Wextra) 16 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @udacity/active-public-content -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Udacity 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: format test build 3 | 4 | .PHONY: format 5 | format: 6 | clang-format src/* include/* -i 7 | 8 | .PHONY: build 9 | build: 10 | mkdir -p build 11 | cd build && \ 12 | cmake .. && \ 13 | make 14 | 15 | .PHONY: debug 16 | debug: 17 | mkdir -p build 18 | cd build && \ 19 | cmake -DCMAKE_BUILD_TYPE=debug .. && \ 20 | make 21 | 22 | .PHONY: clean 23 | clean: 24 | rm -rf build 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CppND-System-Monitor 2 | 3 | Starter code for System Monitor Project in the Object Oriented Programming Course of the [Udacity C++ Nanodegree Program](https://www.udacity.com/course/c-plus-plus-nanodegree--nd213). 4 | 5 | Follow along with the classroom lesson to complete the project! 6 | 7 | ![System Monitor](images/monitor.png) 8 | 9 | ## Udacity Linux Workspace 10 | [Udacity](https://www.udacity.com/) provides a browser-based Linux [Workspace](https://engineering.udacity.com/creating-a-gpu-enhanced-virtual-desktop-for-udacity-497bdd91a505) for students. 11 | 12 | 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. 13 | 14 | ## ncurses 15 | [ncurses](https://www.gnu.org/software/ncurses/) is a library that facilitates text-based graphical output in the terminal. This project relies on ncurses for display output. 16 | 17 | Within the Udacity Workspace, `.student_bashrc` automatically installs ncurses every time you launch the Workspace. 18 | 19 | If you are not using the Workspace, install ncurses within your own Linux environment: `sudo apt install libncurses5-dev libncursesw5-dev` 20 | 21 | ## Make 22 | This project uses [Make](https://www.gnu.org/software/make/). The Makefile has four targets: 23 | * `build` compiles the source code and generates an executable 24 | * `format` applies [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) to style the source code 25 | * `debug` compiles the source code and generates an executable, including debugging symbols 26 | * `clean` deletes the `build/` directory, including all of the build artifacts 27 | 28 | ## Instructions 29 | 30 | 1. Clone the project repository: `git clone https://github.com/udacity/CppND-System-Monitor-Project-Updated.git` 31 | 32 | 2. Build the project: `make build` 33 | 34 | 3. Run the resulting executable: `./build/monitor` 35 | ![Starting System Monitor](images/starting_monitor.png) 36 | 37 | 4. Follow along with the lesson. 38 | 39 | 5. Implement the `System`, `Process`, and `Processor` classes, as well as functions within the `LinuxParser` namespace. 40 | 41 | 6. Submit! -------------------------------------------------------------------------------- /images/monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udacity/CppND-System-Monitor/284b7154b4a8d447c494b1f41d0df2d68b00b909/images/monitor.png -------------------------------------------------------------------------------- /images/starting_monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udacity/CppND-System-Monitor/284b7154b4a8d447c494b1f41d0df2d68b00b909/images/starting_monitor.png -------------------------------------------------------------------------------- /include/format.h: -------------------------------------------------------------------------------- 1 | #ifndef FORMAT_H 2 | #define FORMAT_H 3 | 4 | #include 5 | 6 | namespace Format { 7 | std::string ElapsedTime(long times); // TODO: See src/format.cpp 8 | }; // namespace Format 9 | 10 | #endif -------------------------------------------------------------------------------- /include/linux_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSTEM_PARSER_H 2 | #define SYSTEM_PARSER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace LinuxParser { 9 | // Paths 10 | const std::string kProcDirectory{"/proc/"}; 11 | const std::string kCmdlineFilename{"/cmdline"}; 12 | const std::string kCpuinfoFilename{"/cpuinfo"}; 13 | const std::string kStatusFilename{"/status"}; 14 | const std::string kStatFilename{"/stat"}; 15 | const std::string kUptimeFilename{"/uptime"}; 16 | const std::string kMeminfoFilename{"/meminfo"}; 17 | const std::string kVersionFilename{"/version"}; 18 | const std::string kOSPath{"/etc/os-release"}; 19 | const std::string kPasswordPath{"/etc/passwd"}; 20 | 21 | // System 22 | float MemoryUtilization(); 23 | long UpTime(); 24 | std::vector Pids(); 25 | int TotalProcesses(); 26 | int RunningProcesses(); 27 | std::string OperatingSystem(); 28 | std::string Kernel(); 29 | 30 | // CPU 31 | enum CPUStates { 32 | kUser_ = 0, 33 | kNice_, 34 | kSystem_, 35 | kIdle_, 36 | kIOwait_, 37 | kIRQ_, 38 | kSoftIRQ_, 39 | kSteal_, 40 | kGuest_, 41 | kGuestNice_ 42 | }; 43 | std::vector CpuUtilization(); 44 | long Jiffies(); 45 | long ActiveJiffies(); 46 | long ActiveJiffies(int pid); 47 | long IdleJiffies(); 48 | 49 | // Processes 50 | std::string Command(int pid); 51 | std::string Ram(int pid); 52 | std::string Uid(int pid); 53 | std::string User(int pid); 54 | long int UpTime(int pid); 55 | }; // namespace LinuxParser 56 | 57 | #endif -------------------------------------------------------------------------------- /include/ncurses_display.h: -------------------------------------------------------------------------------- 1 | #ifndef NCURSES_DISPLAY_H 2 | #define NCURSES_DISPLAY_H 3 | 4 | #include 5 | 6 | #include "process.h" 7 | #include "system.h" 8 | 9 | namespace NCursesDisplay { 10 | void Display(System& system, int n = 10); 11 | void DisplaySystem(System& system, WINDOW* window); 12 | void DisplayProcesses(std::vector& processes, WINDOW* window, int n); 13 | std::string ProgressBar(float percent); 14 | }; // namespace NCursesDisplay 15 | 16 | #endif -------------------------------------------------------------------------------- /include/process.h: -------------------------------------------------------------------------------- 1 | #ifndef PROCESS_H 2 | #define PROCESS_H 3 | 4 | #include 5 | /* 6 | Basic class for Process representation 7 | It contains relevant attributes as shown below 8 | */ 9 | class Process { 10 | public: 11 | int Pid(); // TODO: See src/process.cpp 12 | std::string User(); // TODO: See src/process.cpp 13 | std::string Command(); // TODO: See src/process.cpp 14 | float CpuUtilization(); // TODO: See src/process.cpp 15 | std::string Ram(); // TODO: See src/process.cpp 16 | long int UpTime(); // TODO: See src/process.cpp 17 | bool operator<(Process const& a) const; // TODO: See src/process.cpp 18 | 19 | // TODO: Declare any necessary private members 20 | private: 21 | }; 22 | 23 | #endif -------------------------------------------------------------------------------- /include/processor.h: -------------------------------------------------------------------------------- 1 | #ifndef PROCESSOR_H 2 | #define PROCESSOR_H 3 | 4 | class Processor { 5 | public: 6 | float Utilization(); // TODO: See src/processor.cpp 7 | 8 | // TODO: Declare any necessary private members 9 | private: 10 | }; 11 | 12 | #endif -------------------------------------------------------------------------------- /include/system.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSTEM_H 2 | #define SYSTEM_H 3 | 4 | #include 5 | #include 6 | 7 | #include "process.h" 8 | #include "processor.h" 9 | 10 | class System { 11 | public: 12 | Processor& Cpu(); // TODO: See src/system.cpp 13 | std::vector& Processes(); // TODO: See src/system.cpp 14 | float MemoryUtilization(); // TODO: See src/system.cpp 15 | long UpTime(); // TODO: See src/system.cpp 16 | int TotalProcesses(); // TODO: See src/system.cpp 17 | int RunningProcesses(); // TODO: See src/system.cpp 18 | std::string Kernel(); // TODO: See src/system.cpp 19 | std::string OperatingSystem(); // TODO: See src/system.cpp 20 | 21 | // TODO: Define any necessary private members 22 | private: 23 | Processor cpu_ = {}; 24 | std::vector processes_ = {}; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /src/format.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "format.h" 4 | 5 | using std::string; 6 | 7 | // TODO: Complete this helper function 8 | // INPUT: Long int measuring seconds 9 | // OUTPUT: HH:MM:SS 10 | // REMOVE: [[maybe_unused]] once you define the function 11 | string Format::ElapsedTime(long seconds[[maybe_unused]]) { return string(); } -------------------------------------------------------------------------------- /src/linux_parser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "linux_parser.h" 8 | 9 | using std::stof; 10 | using std::string; 11 | using std::to_string; 12 | using std::vector; 13 | 14 | // DONE: An example of how to read data from the filesystem 15 | string LinuxParser::OperatingSystem() { 16 | string line; 17 | string key; 18 | string value; 19 | std::ifstream filestream(kOSPath); 20 | if (filestream.is_open()) { 21 | while (std::getline(filestream, line)) { 22 | std::replace(line.begin(), line.end(), ' ', '_'); 23 | std::replace(line.begin(), line.end(), '=', ' '); 24 | std::replace(line.begin(), line.end(), '"', ' '); 25 | std::istringstream linestream(line); 26 | while (linestream >> key >> value) { 27 | if (key == "PRETTY_NAME") { 28 | std::replace(value.begin(), value.end(), '_', ' '); 29 | return value; 30 | } 31 | } 32 | } 33 | } 34 | return value; 35 | } 36 | 37 | // DONE: An example of how to read data from the filesystem 38 | string LinuxParser::Kernel() { 39 | string os, kernel, version; 40 | string line; 41 | std::ifstream stream(kProcDirectory + kVersionFilename); 42 | if (stream.is_open()) { 43 | std::getline(stream, line); 44 | std::istringstream linestream(line); 45 | linestream >> os >> version >> kernel; 46 | } 47 | return kernel; 48 | } 49 | 50 | // BONUS: Update this to use std::filesystem 51 | vector LinuxParser::Pids() { 52 | vector pids; 53 | DIR* directory = opendir(kProcDirectory.c_str()); 54 | struct dirent* file; 55 | while ((file = readdir(directory)) != nullptr) { 56 | // Is this a directory? 57 | if (file->d_type == DT_DIR) { 58 | // Is every character of the name a digit? 59 | string filename(file->d_name); 60 | if (std::all_of(filename.begin(), filename.end(), isdigit)) { 61 | int pid = stoi(filename); 62 | pids.push_back(pid); 63 | } 64 | } 65 | } 66 | closedir(directory); 67 | return pids; 68 | } 69 | 70 | // TODO: Read and return the system memory utilization 71 | float LinuxParser::MemoryUtilization() { return 0.0; } 72 | 73 | // TODO: Read and return the system uptime 74 | long LinuxParser::UpTime() { return 0; } 75 | 76 | // TODO: Read and return the number of jiffies for the system 77 | long LinuxParser::Jiffies() { return 0; } 78 | 79 | // TODO: Read and return the number of active jiffies for a PID 80 | // REMOVE: [[maybe_unused]] once you define the function 81 | long LinuxParser::ActiveJiffies(int pid[[maybe_unused]]) { return 0; } 82 | 83 | // TODO: Read and return the number of active jiffies for the system 84 | long LinuxParser::ActiveJiffies() { return 0; } 85 | 86 | // TODO: Read and return the number of idle jiffies for the system 87 | long LinuxParser::IdleJiffies() { return 0; } 88 | 89 | // TODO: Read and return CPU utilization 90 | vector LinuxParser::CpuUtilization() { return {}; } 91 | 92 | // TODO: Read and return the total number of processes 93 | int LinuxParser::TotalProcesses() { return 0; } 94 | 95 | // TODO: Read and return the number of running processes 96 | int LinuxParser::RunningProcesses() { return 0; } 97 | 98 | // TODO: Read and return the command associated with a process 99 | // REMOVE: [[maybe_unused]] once you define the function 100 | string LinuxParser::Command(int pid[[maybe_unused]]) { return string(); } 101 | 102 | // TODO: Read and return the memory used by a process 103 | // REMOVE: [[maybe_unused]] once you define the function 104 | string LinuxParser::Ram(int pid[[maybe_unused]]) { return string(); } 105 | 106 | // TODO: Read and return the user ID associated with a process 107 | // REMOVE: [[maybe_unused]] once you define the function 108 | string LinuxParser::Uid(int pid[[maybe_unused]]) { return string(); } 109 | 110 | // TODO: Read and return the user associated with a process 111 | // REMOVE: [[maybe_unused]] once you define the function 112 | string LinuxParser::User(int pid[[maybe_unused]]) { return string(); } 113 | 114 | // TODO: Read and return the uptime of a process 115 | // REMOVE: [[maybe_unused]] once you define the function 116 | long LinuxParser::UpTime(int pid[[maybe_unused]]) { return 0; } 117 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ncurses_display.h" 2 | #include "system.h" 3 | 4 | int main() { 5 | System system; 6 | NCursesDisplay::Display(system); 7 | } -------------------------------------------------------------------------------- /src/ncurses_display.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "format.h" 8 | #include "ncurses_display.h" 9 | #include "system.h" 10 | 11 | using std::string; 12 | using std::to_string; 13 | 14 | // 50 bars uniformly displayed from 0 - 100 % 15 | // 2% is one bar(|) 16 | std::string NCursesDisplay::ProgressBar(float percent) { 17 | std::string result{"0%"}; 18 | int size{50}; 19 | float bars{percent * size}; 20 | 21 | for (int i{0}; i < size; ++i) { 22 | result += i <= bars ? '|' : ' '; 23 | } 24 | 25 | string display{to_string(percent * 100).substr(0, 4)}; 26 | if (percent < 0.1 || percent == 1.0) 27 | display = " " + to_string(percent * 100).substr(0, 3); 28 | return result + " " + display + "/100%"; 29 | } 30 | 31 | void NCursesDisplay::DisplaySystem(System& system, WINDOW* window) { 32 | int row{0}; 33 | mvwprintw(window, ++row, 2, "%s", ("OS: " + system.OperatingSystem()).c_str()); 34 | mvwprintw(window, ++row, 2, "%s", ("Kernel: " + system.Kernel()).c_str()); 35 | mvwprintw(window, ++row, 2, "CPU: "); 36 | wattron(window, COLOR_PAIR(1)); 37 | mvwprintw(window, row, 10, "%s", ""); 38 | wprintw(window, "%s", ProgressBar(system.Cpu().Utilization()).c_str()); 39 | wattroff(window, COLOR_PAIR(1)); 40 | mvwprintw(window, ++row, 2, "Memory: "); 41 | wattron(window, COLOR_PAIR(1)); 42 | mvwprintw(window, row, 10, "%s", ""); 43 | wprintw(window, "%s", ProgressBar(system.MemoryUtilization()).c_str()); 44 | wattroff(window, COLOR_PAIR(1)); 45 | mvwprintw(window, ++row, 2, "%s", 46 | ("Total Processes: " + to_string(system.TotalProcesses())).c_str()); 47 | mvwprintw( 48 | window, ++row, 2, "%s", 49 | ("Running Processes: " + to_string(system.RunningProcesses())).c_str()); 50 | mvwprintw(window, ++row, 2, "%s", 51 | ("Up Time: " + Format::ElapsedTime(system.UpTime())).c_str()); 52 | wrefresh(window); 53 | } 54 | 55 | void NCursesDisplay::DisplayProcesses(std::vector& processes, 56 | WINDOW* window, int n) { 57 | int row{0}; 58 | int const pid_column{2}; 59 | int const user_column{9}; 60 | int const cpu_column{16}; 61 | int const ram_column{26}; 62 | int const time_column{35}; 63 | int const command_column{46}; 64 | wattron(window, COLOR_PAIR(2)); 65 | mvwprintw(window, ++row, pid_column, "PID"); 66 | mvwprintw(window, row, user_column, "USER"); 67 | mvwprintw(window, row, cpu_column, "CPU[%%]"); 68 | mvwprintw(window, row, ram_column, "RAM[MB]"); 69 | mvwprintw(window, row, time_column, "TIME+"); 70 | mvwprintw(window, row, command_column, "COMMAND"); 71 | wattroff(window, COLOR_PAIR(2)); 72 | for (int i = 0; i < n; ++i) { 73 | //You need to take care of the fact that the cpu utilization has already been multiplied by 100. 74 | // Clear the line 75 | mvwprintw(window, ++row, pid_column, (string(window->_maxx-2, ' ').c_str())); 76 | 77 | mvwprintw(window, row, pid_column, "%s", to_string(processes[i].Pid()).c_str()); 78 | mvwprintw(window, row, user_column, "%s", processes[i].User().c_str()); 79 | float cpu = processes[i].CpuUtilization() * 100; 80 | mvwprintw(window, row, cpu_column, "%s", to_string(cpu).substr(0, 4).c_str()); 81 | mvwprintw(window, row, ram_column, "%s", processes[i].Ram().c_str()); 82 | mvwprintw(window, row, time_column, "%s", 83 | Format::ElapsedTime(processes[i].UpTime()).c_str()); 84 | mvwprintw(window, row, command_column, "%s", 85 | processes[i].Command().substr(0, window->_maxx - 46).c_str()); 86 | } 87 | } 88 | 89 | void NCursesDisplay::Display(System& system, int n) { 90 | initscr(); // start ncurses 91 | noecho(); // do not print input values 92 | cbreak(); // terminate ncurses on ctrl + c 93 | start_color(); // enable color 94 | 95 | int x_max{getmaxx(stdscr)}; 96 | WINDOW* system_window = newwin(9, x_max - 1, 0, 0); 97 | WINDOW* process_window = 98 | newwin(3 + n, x_max - 1, system_window->_maxy + 1, 0); 99 | 100 | while (1) { 101 | init_pair(1, COLOR_BLUE, COLOR_BLACK); 102 | init_pair(2, COLOR_GREEN, COLOR_BLACK); 103 | box(system_window, 0, 0); 104 | box(process_window, 0, 0); 105 | DisplaySystem(system, system_window); 106 | DisplayProcesses(system.Processes(), process_window, n); 107 | wrefresh(system_window); 108 | wrefresh(process_window); 109 | refresh(); 110 | std::this_thread::sleep_for(std::chrono::seconds(1)); 111 | } 112 | endwin(); 113 | } 114 | -------------------------------------------------------------------------------- /src/process.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "process.h" 8 | 9 | using std::string; 10 | using std::to_string; 11 | using std::vector; 12 | 13 | // TODO: Return this process's ID 14 | int Process::Pid() { return 0; } 15 | 16 | // TODO: Return this process's CPU utilization 17 | float Process::CpuUtilization() { return 0; } 18 | 19 | // TODO: Return the command that generated this process 20 | string Process::Command() { return string(); } 21 | 22 | // TODO: Return this process's memory utilization 23 | string Process::Ram() { return string(); } 24 | 25 | // TODO: Return the user (name) that generated this process 26 | string Process::User() { return string(); } 27 | 28 | // TODO: Return the age of this process (in seconds) 29 | long int Process::UpTime() { return 0; } 30 | 31 | // TODO: Overload the "less than" comparison operator for Process objects 32 | // REMOVE: [[maybe_unused]] once you define the function 33 | bool Process::operator<(Process const& a[[maybe_unused]]) const { return true; } -------------------------------------------------------------------------------- /src/processor.cpp: -------------------------------------------------------------------------------- 1 | #include "processor.h" 2 | 3 | // TODO: Return the aggregate CPU utilization 4 | float Processor::Utilization() { return 0.0; } -------------------------------------------------------------------------------- /src/system.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "process.h" 8 | #include "processor.h" 9 | #include "system.h" 10 | 11 | using std::set; 12 | using std::size_t; 13 | using std::string; 14 | using std::vector; 15 | /*You need to complete the mentioned TODOs in order to satisfy the rubric criteria "The student will be able to extract and display basic data about the system." 16 | 17 | You need to properly format the uptime. Refer to the comments mentioned in format. cpp for formatting the uptime.*/ 18 | 19 | // TODO: Return the system's CPU 20 | Processor& System::Cpu() { return cpu_; } 21 | 22 | // TODO: Return a container composed of the system's processes 23 | vector& System::Processes() { return processes_; } 24 | 25 | // TODO: Return the system's kernel identifier (string) 26 | std::string System::Kernel() { return string(); } 27 | 28 | // TODO: Return the system's memory utilization 29 | float System::MemoryUtilization() { return 0.0; } 30 | 31 | // TODO: Return the operating system name 32 | std::string System::OperatingSystem() { return string(); } 33 | 34 | // TODO: Return the number of processes actively running on the system 35 | int System::RunningProcesses() { return 0; } 36 | 37 | // TODO: Return the total number of processes on the system 38 | int System::TotalProcesses() { return 0; } 39 | 40 | // TODO: Return the number of seconds since the system started running 41 | long int System::UpTime() { return 0; } 42 | --------------------------------------------------------------------------------