0

Hi all,

I want to write a program in python to capture memory and cpu readings of a process which is running on linux server and save the readings in a tabular format to any .doc or .csv file. Got to know that 'top' command would give the cpu and memory readings which a process occupies/utilises on the linux server. As I am quite new to Python, I am not sure what functions can be used to achieve this requirement.

Is this very simple program to do it, can someone guide/help me in it. Also,can someone share me a sample python script if any such available.

Thanks,
Sara

2
Contributors
1
Reply
26
Views
1 Year
Discussion Span
Last Post by Gribouillis
1

There is a great module named <psutil> which can tell you all this

import psutil

for proc in psutil.process_iter():
    try:
        pinfo = proc.as_dict()
    except psutil.NoSuchProcess:
        pass
    else:
        print(pinfo)
        break

To save the data into tabular format, you could use a simple library such as <tablib>.

Edited by Gribouillis

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.