Lab 1 - Week 1 - Monitoring Process Memory Usage
Due: Sunday September 14
FIRST: See
labs.html
for information on labs.
Copy the lab 1 sample code from
https://github.com/jsellens/unx511_samples/tree/main/lab_01
(or clone/update the unx511_samples repository).
Information on all processes running on a Linux system is contained within the /proc directory. All directories under /proc which are digits represent a process.
If you issue the command ps aux you will see all processes that are running. You can also see the processes ordered by cpu usage by issuing the command top.
In this lab, you will write a C/CPP program to scan all processes running on the system and report on those which have used more than 10Mbytes of resident memory.
You can do this by going through each process directory in /proc and looking at the file status. For instance, let's say you want to look at the
status information for process 10167:
$ cd /proc/10167
$ vim status
Inside the file status are variables such as Name: (the process name) and Pid: (the process pid).
Virtual Memory is represented by VmSize: and Resident memory is represented by VmRSS:
- Write and execute a C/CPP program that will scan every directory in /proc that represents a process
(each directory that begin with a number represents a process). Open the file status.
If VmRSS: is greater than 10000 kB, then print out the process name, the process id and the memory used.
See the code at the following link as an example on how to get all files in a directory:
https://www.unix.com/programming/33263-unix-c-get-files-folder.html.
- Open a second command line and execute the command top which orders processes by cpu usage.
$ top
Compare the processes reported in top with those reported by your program. You can cancel the execution of top with ctrl-c or q.
See the following link for an explanation of top:
https://linux.die.net/man/1/top.
- In a text file named question3.txt, explain the difference between virtual memory and resident memory. What is virtual memory? What is resident memory?
- In a text file named question4.txt, research and report on any of the three of the processes returned by your program. Simply explain what these processes do.
The following web-page contains detailed information about each of the files under /proc:
proc - process information pseudo-filesystem: https://linux.die.net/sag/proc-fs.html.
Sample source code that retrieves system information such as model name, cpu speed, memory usage, processes running/blocked, up time and idle time can be seen at
MemMonitor.cpp
Lab Submission:
- Follow the instructions above
- Send email
- To: john.sellens@senecapolytechnic.ca
- Subject: lab 1 submission
- Attach your cpp program file, Makefile, question3.txt, and
question4.txt files
- Do not attempt to send a zip file - won't be accepted
- Submit lab 1 through blackboard at
https://learn.senecapolytechnic.ca/
UNX511 NSC Class Links
References
Tools
Links