Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- MAXMEM_1=800000
- MAXMEM_2=1300000
- IDLE=300000
- export DISPLAY=:0
- function getmem {
- mem=`ps -ef -orss=,args= | sort -b -k1,1n | pr -TW128 | grep gnome-shell | grep USER=$USER | cut -d" " -f1 | tail -n 1`
- if [ -z $mem ]; then
- mem=`ps -ef -orss=,args= | sort -b -k1,1n | pr -TW128 | grep "gnome-shell --replace" | cut -d" " -f1 | tr -d '\n' | tail -n 1`
- fi
- echo $mem
- }
- while [ 1 ]; do
- if [ -e /tmp/resetgnome ]; then
- rm -f /tmp/resetgnome
- dbus-send --type=method_call --print-reply --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval string:'global.reexec_self()'
- fi
- sleep 1
- done &
- while [ 1 ]; do
- mem=$(getmem)
- echo MEM=$mem
- if [ $mem -gt $MAXMEM_1 ]; then
- echo "time to reset gnome-shell"
- while [ 1 ]; do
- mem=$(getmem)
- idle=`export DISPLAY=:1; xprintidle`
- echo "IDLE: $idle MEM: $mem"
- if [ $idle -gt $IDLE ] || [ $mem -gt $MAXMEM_2 ]; then
- wk=0
- d=`date +'%s'`
- if [ -f /tmp/woke ]; then
- wk=`cat /tmp/woke`
- fi
- r=$(($d-$wk))
- if [ $r -gt 60 ]; then
- export DISPLAY=:1
- touch /tmp/resetgnome
- break
- else
- echo "resumed recently"
- fi
- fi
- sleep 1
- export DISPLAY=:1
- fixgamma
- done
- fi
- export DISPLAY=:1
- fixgamma
- sleep 3
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement