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

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>.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.