persinammon / htop-linux-system-monitor

htop utility: reads from text files on Linux OS to display process information with GUI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

htop

This project practices object oriented programming in C++, using the htop process viewer for a Linux file system as the project goal. My contributions within the source code are marked under TODO's.

Notes

  • Interestingly, LinuxParser was implemented as a namespace. There's no object level data/need for multiple instantiations, so it makes sense to give it some more implicit structure that way. The constant string paths are very interesting to read, as they are how system data is stored in memory on a Linux OS.
  • The project is basically reading from text files with process and memory utilization information stored and organized by the Linux OS. There are decisions such as whether to read once then cache the result in the object instance or to have a pass-through function where each time it is called the file is read again. There is an instance of an overloaded less than operator to compare one process to the process with the method called, allowing the sort function to sort processes by X metric.
  • I wrote a bit on why the project authors made a parsing decision here.
  • The authors originally used this attribute specifier to suppress compiler warnings about unused methods: [[maybe_unused]](since C++17), which was interesting to see. Example usage: long LinuxParser::UpTime(int pid[[maybe_unused]]) { return 0; }

Resources

I quite liked these links shared by Udacity for understanding the files:

ncurses

ncurses is a library that facilitates text-based graphical output in the terminal. This project relies on ncurses for display output.

The original htop uses ncurses too.

Install ncurses within your own Linux environment using sudo apt install libncurses5-dev libncursesw5-dev.

Make

This project uses Make. The Makefile has four targets:

  • build compiles the source code and generates an executable
  • format applies ClangFormat to style the source code
  • debug compiles the source code and generates an executable, including debugging symbols
  • clean deletes the build/ directory, including all of the build artifacts

If you look inside the Makefile, it calls CMake then calls Make again. The authors mentioned they wrote it using CMake in case the student wants to extend this to a Windows filesystem.

How to Run

  1. make build to build the project.

  2. ./build/monitor to run the generated executable.

About

htop utility: reads from text files on Linux OS to display process information with GUI

License:MIT License


Languages

Language:C++ 97.0%Language:CMake 1.7%Language:Makefile 1.2%