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
The following function can be used to get the resources for a process.