Skip to content

Latest commit

 

History

History
71 lines (56 loc) · 2.59 KB

README.md

File metadata and controls

71 lines (56 loc) · 2.59 KB

About

This program reports on different metrics and information of the system it is run on. Similar to a Task Manager for Windows or btop for Linux.

This program is meant to be run on a Linux operating system (WSL on Windows works as well), as it makes use of Linux system files such as proc/cpuinfo and more.

Example

Screenshot of system monitoring tool

Installation

  1. Clone the repo
git clone https://github.com/andre-fong/System-Monitoring-Tool.git
  1. Compile
gcc system_monitor.c
  1. Run
./a.out

How to Run

When running, the following command line arguments are accepted:

  • --system
    • Only generate system-related information
  • --user
    • Only generate user-related information
  • --graphics
    • Include graphical output for CPU and memory usage
  • --sequential
    • Generate output sequentially (useful for redirecting output to a file)
    • E.g., ./a.out --sequential > output.txt
  • --samples=N
    • Program takes N samples (default: 10)
    • Available as positional argument
  • --tdelay=T
    • Delay T seconds in between each data sample (default: 1)
    • Available as positional argument

Example Usage

./a.out --graphics --sequential 3 5 > output.txt

Run the system monitoring tool with graphics and output data sequentially, with 3 samples each 5 seconds apart. Redirect the output of the program to output.txt.

Implementation

To get system data from Linux in C, I included a collection of Linux libraries and read from specific system files. Notable mentions include:

  • sys/resource.h (getrusage())
    • This was important in seeing how much memory the calling process (our system monitoring program) was using.
  • sys/utsname.h (uname())
    • This was important in getting system information like the system name, machine name, version, release, and architecture.
  • sys/sysinfo.h (sysinfo())
    • This was important in seeing total uptime since last reboot.
    • It was also important in reading memory usage throughout the system.
  • utmp.h
    • This file defined the utmp struct, which was important in parsing through the system file “/var/run/utmp”, where data on users that use the system is located.
  • /proc/cpuinfo
    • This system file allowed me to get the number of cpu cores in the system.
  • /proc/stat
    • This system file allowed me to calculate the cpu usage by finding the delta of the cpu idle and busy times over a period of 1 second.