SemoxyMC / Server

The backend code for Semoxy
GNU General Public License v3.0
0 stars 0 forks source link

show ram and cpu usage #21

Closed xImAnton closed 3 years ago

xImAnton commented 3 years ago

The following function can be used to get the resources for a process.

def get_resources(pid):
    cpu = float(sp.check_output(f"ps -p {pid} -o %cpu", shell=True).split()[-1].strip())
    with open(f"/proc/{pid}/statm") as f:
        ram = int(f.read().split()[0])
    return ram, cpu