Linux track memory usage of process

broken image
broken image

Procpath can be used to record Procfs metrics of an application (process trees) including CPU usage and Resident Set Size (RSS). The program quits when you hit Ctrl+C or when the process is killed. You can then redirect its output to a file in order to import it into a spreadsheet later ( python log.py 9391 > firefox_log.txt) and import the data into a spreadsheet selecting Tab as your separator.

broken image

It will print the cpu usage and ram usage in per cent two times a second: %CPU %MEM

broken image

You first need to find out the process id of the program you want to monitor, then you can run the script with the PID as an argument: python log.py 3912 If not len(sys.argv) = 2 or not all(i in string.digits for i in sys.argv): Return (float(d.split()), float(d.split())) if d else None This simple python script should do what you want: import timeĭ = [i for i in commands.getoutput('ps aux').split('\n')

broken image