├── .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: ${{ github.repository }} | 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 | set(CURSES_NEED_NCURSES TRUE) 5 | find_package(Curses REQUIRED) 6 | include_directories(${CURSES_INCLUDE_DIRS}) 7 | 8 | include_directories(include) 9 | file(GLOB SOURCES "src/*.cpp") 10 | 11 | add_executable(monitor ${SOURCES}) 12 | 13 | set_property(TARGET monitor PROPERTY CXX_STANDARD 17) 14 | target_link_libraries(monitor ${CURSES_LIBRARIES}) 15 | # TODO: Run -Werror in CI. 16 | target_compile_options(monitor PRIVATE -Wall -Wextra) 17 | -------------------------------------------------------------------------------- /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-Project-Updated/c96970566df9108ee414e7be6f29f1ffb4fb8d66/images/monitor.png -------------------------------------------------------------------------------- /images/starting_monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udacity/CppND-System-Monitor-Project-Updated/c96970566df9108ee414e7be6f29f1ffb4fb8d66/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 | 6 | #include "linux_parser.h" 7 | 8 | using std::stof; 9 | using std::string; 10 | using std::to_string; 11 | using std::vector; 12 | 13 | // DONE: An example of how to read data from the filesystem 14 | string LinuxParser::OperatingSystem() { 15 | string line; 16 | string key; 17 | string value; 18 | std::ifstream filestream(kOSPath); 19 | if (filestream.is_open()) { 20 | while (std::getline(filestream, line)) { 21 | std::replace(line.begin(), line.end(), ' ', '_'); 22 | std::replace(line.begin(), line.end(), '=', ' '); 23 | std::replace(line.begin(), line.end(), '"', ' '); 24 | std::istringstream linestream(line); 25 | while (linestream >> key >> value) { 26 | if (key == "PRETTY_NAME") { 27 | std::replace(value.begin(), value.end(), '_', ' '); 28 | return value; 29 | } 30 | } 31 | } 32 | } 33 | return value; 34 | } 35 | 36 | // DONE: An example of how to read data from the filesystem 37 | string LinuxParser::Kernel() { 38 | string os, version, kernel; 39 | string line; 40 | std::ifstream stream(kProcDirectory + kVersionFilename); 41 | if (stream.is_open()) { 42 | std::getline(stream, line); 43 | std::istringstream linestream(line); 44 | linestream >> os >> version >> kernel; 45 | } 46 | return kernel; 47 | } 48 | 49 | // BONUS: Update this to use std::filesystem 50 | vector LinuxParser::Pids() { 51 | vector pids; 52 | DIR* directory = opendir(kProcDirectory.c_str()); 53 | struct dirent* file; 54 | while ((file = readdir(directory)) != nullptr) { 55 | // Is this a directory? 56 | if (file->d_type == DT_DIR) { 57 | // Is every character of the name a digit? 58 | string filename(file->d_name); 59 | if (std::all_of(filename.begin(), filename.end(), isdigit)) { 60 | int pid = stoi(filename); 61 | pids.push_back(pid); 62 | } 63 | } 64 | } 65 | closedir(directory); 66 | return pids; 67 | } 68 | 69 | // TODO: Read and return the system memory utilization 70 | float LinuxParser::MemoryUtilization() { return 0.0; } 71 | 72 | // TODO: Read and return the system uptime 73 | long LinuxParser::UpTime() { return 0; } 74 | 75 | // TODO: Read and return the number of jiffies for the system 76 | long LinuxParser::Jiffies() { return 0; } 77 | 78 | // TODO: Read and return the number of active jiffies for a PID 79 | // REMOVE: [[maybe_unused]] once you define the function 80 | long LinuxParser::ActiveJiffies(int pid[[maybe_unused]]) { return 0; } 81 | 82 | // TODO: Read and return the number of active jiffies for the system 83 | long LinuxParser::ActiveJiffies() { return 0; } 84 | 85 | // TODO: Read and return the number of idle jiffies for the system 86 | long LinuxParser::IdleJiffies() { return 0; } 87 | 88 | // TODO: Read and return CPU utilization 89 | vector LinuxParser::CpuUtilization() { return {}; } 90 | 91 | // TODO: Read and return the total number of processes 92 | int LinuxParser::TotalProcesses() { return 0; } 93 | 94 | // TODO: Read and return the number of running processes 95 | int LinuxParser::RunningProcesses() { return 0; } 96 | 97 | // TODO: Read and return the command associated with a process 98 | // REMOVE: [[maybe_unused]] once you define the function 99 | string LinuxParser::Command(int pid[[maybe_unused]]) { return string(); } 100 | 101 | // TODO: Read and return the memory used by a process 102 | // REMOVE: [[maybe_unused]] once you define the function 103 | string LinuxParser::Ram(int pid[[maybe_unused]]) { return string(); } 104 | 105 | // TODO: Read and return the user ID associated with a process 106 | // REMOVE: [[maybe_unused]] once you define the function 107 | string LinuxParser::Uid(int pid[[maybe_unused]]) { return string(); } 108 | 109 | // TODO: Read and return the user associated with a process 110 | // REMOVE: [[maybe_unused]] once you define the function 111 | string LinuxParser::User(int pid[[maybe_unused]]) { return string(); } 112 | 113 | // TODO: Read and return the uptime of a process 114 | // REMOVE: [[maybe_unused]] once you define the function 115 | long LinuxParser::UpTime(int pid[[maybe_unused]]) { return 0; } 116 | -------------------------------------------------------------------------------- /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, ("OS: " + system.OperatingSystem()).c_str()); 34 | mvwprintw(window, ++row, 2, ("Kernel: " + system.Kernel()).c_str()); 35 | mvwprintw(window, ++row, 2, "CPU: "); 36 | wattron(window, COLOR_PAIR(1)); 37 | mvwprintw(window, row, 10, ""); 38 | wprintw(window, 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, ""); 43 | wprintw(window, ProgressBar(system.MemoryUtilization()).c_str()); 44 | wattroff(window, COLOR_PAIR(1)); 45 | mvwprintw(window, ++row, 2, 46 | ("Total Processes: " + to_string(system.TotalProcesses())).c_str()); 47 | mvwprintw( 48 | window, ++row, 2, 49 | ("Running Processes: " + to_string(system.RunningProcesses())).c_str()); 50 | mvwprintw(window, ++row, 2, 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 | int const num_processes = int(processes.size()) > n ? n : processes.size(); 73 | for (int i = 0; i < num_processes; ++i) { 74 | mvwprintw(window, ++row, pid_column, to_string(processes[i].Pid()).c_str()); 75 | mvwprintw(window, row, user_column, processes[i].User().c_str()); 76 | float cpu = processes[i].CpuUtilization() * 100; 77 | mvwprintw(window, row, cpu_column, to_string(cpu).substr(0, 4).c_str()); 78 | mvwprintw(window, row, ram_column, processes[i].Ram().c_str()); 79 | mvwprintw(window, row, time_column, 80 | Format::ElapsedTime(processes[i].UpTime()).c_str()); 81 | mvwprintw(window, row, command_column, 82 | processes[i].Command().substr(0, window->_maxx - 46).c_str()); 83 | } 84 | } 85 | 86 | void NCursesDisplay::Display(System& system, int n) { 87 | initscr(); // start ncurses 88 | noecho(); // do not print input values 89 | cbreak(); // terminate ncurses on ctrl + c 90 | start_color(); // enable color 91 | 92 | int x_max{getmaxx(stdscr)}; 93 | WINDOW* system_window = newwin(9, x_max - 1, 0, 0); 94 | WINDOW* process_window = 95 | newwin(3 + n, x_max - 1, system_window->_maxy + 1, 0); 96 | 97 | while (1) { 98 | init_pair(1, COLOR_BLUE, COLOR_BLACK); 99 | init_pair(2, COLOR_GREEN, COLOR_BLACK); 100 | box(system_window, 0, 0); 101 | box(process_window, 0, 0); 102 | DisplaySystem(system, system_window); 103 | DisplayProcesses(system.Processes(), process_window, n); 104 | wrefresh(system_window); 105 | wrefresh(process_window); 106 | refresh(); 107 | std::this_thread::sleep_for(std::chrono::seconds(1)); 108 | } 109 | endwin(); 110 | } 111 | -------------------------------------------------------------------------------- /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 | 16 | // TODO: Return the system's CPU 17 | Processor& System::Cpu() { return cpu_; } 18 | 19 | // TODO: Return a container composed of the system's processes 20 | vector& System::Processes() { return processes_; } 21 | 22 | // TODO: Return the system's kernel identifier (string) 23 | std::string System::Kernel() { return string(); } 24 | 25 | // TODO: Return the system's memory utilization 26 | float System::MemoryUtilization() { return 0.0; } 27 | 28 | // TODO: Return the operating system name 29 | std::string System::OperatingSystem() { return string(); } 30 | 31 | // TODO: Return the number of processes actively running on the system 32 | int System::RunningProcesses() { return 0; } 33 | 34 | // TODO: Return the total number of processes on the system 35 | int System::TotalProcesses() { return 0; } 36 | 37 | // TODO: Return the number of seconds since the system started running 38 | long int System::UpTime() { return 0; } --------------------------------------------------------------------------------