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.
- Clone the repo
git clone https://github.com/andre-fong/System-Monitoring-Tool.git
- Compile
gcc system_monitor.c
- Run
./a.out
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
./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
.
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.