Skip to content

Instantly share code, notes, and snippets.

@marcellmars
Created February 19, 2012 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcellmars/1863906 to your computer and use it in GitHub Desktop.
Save marcellmars/1863906 to your computer and use it in GitHub Desktop.
Check total memory and if used more than 3.0GB and make desktop notification with programs which use more than 2.0GB
#!/usr/bin/env python2
import commands, pynotify, sys, os, time
while 1:
lines = commands.getoutput('sudo ps_mem.py').split('\n')
total = [float(str(l).split(" ")[-2]) for l in lines if l.startswith(" ") and l.find("GiB")]
progs = [str(l).split("=")[1].strip().split(" ") for l in lines if l.find("GiB") != -1 and not l.startswith(" ")]
for prog in progs:
if float(prog[0]) > 2.0 and total[0] > 3.0:
pynotify.init("Memory usage notification")
notification = pynotify.Notification(prog[0] + " " + prog[1].replace('\t', ' '), "")
notification.show()
time.sleep(300)
@marcellmars
Copy link
Author

i will never learn how to use web broswer with just few tabs. this is a little daemon which notifies me when things get close to screwed up ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment