Skip to content

Instantly share code, notes, and snippets.

@hpanago
Last active December 12, 2015 20:58
Show Gist options
  • Save hpanago/143f03c21d56a77dbd76 to your computer and use it in GitHub Desktop.
Save hpanago/143f03c21d56a77dbd76 to your computer and use it in GitHub Desktop.
Bash script that notifies you when you free memory is 100 MB. Shows process ID and name.
#!/bin/bash
MEM=`cat /proc/meminfo | egrep 'MemFree:' |tr -d '[[:space:]]' | sed '$s/..$//' | cut -d ":" -f2`
USER=`whoami`
PID=`ps -ly --User $USER --sort -rss | sed -n '2p' | tr -s [[:blank:]] | cut -d " " -f3`
NAME=`ps -ly --User $USER --sort -rss | sed -n '2p' | tr -s [[:blank:]] | cut -d " " -f13`
if [ $MEM -lt 102400 ]; then
DISPLAY=:0 notify-send "Low memory. #1 process in RAM usage: $NAME with PID: $PID"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment