Guest User

swap.py

a guest
Jul 14th, 2019
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python3
  2.  
  3. import os
  4.  
  5. pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
  6.  
  7. gesamt = 0
  8. output = []
  9.  
  10. for pid in pids:
  11.   f = open("/proc/%s/status" % pid, "r")
  12.   line = f.readline()
  13.   name = line
  14.  
  15.   for line in f:
  16.     if "VmSwap:" in line and "0 kB" not in line:
  17.       string = name.split()[1]+": "+line.split()[1]+" kB"
  18.       output.append(string)
  19.       gesamt = gesamt + int(line.split()[1].strip())
  20.  
  21.   f.close
  22.  
  23. for x in sorted(output, key=str.lower):
  24.   print(x)
  25.  
  26. print()
  27. print("Gesamt: "+str(gesamt)+" kB")
RAW Paste Data