Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. MAXMEM_1=800000
  4. MAXMEM_2=1300000
  5. IDLE=300000
  6. export DISPLAY=:0
  7.  
  8. function getmem {
  9. mem=`ps -ef -orss=,args= | sort -b -k1,1n | pr -TW128 | grep gnome-shell | grep USER=$USER | cut -d" " -f1 | tail -n 1`
  10. if [ -z $mem ]; then
  11. mem=`ps -ef -orss=,args= | sort -b -k1,1n | pr -TW128 | grep "gnome-shell --replace" | cut -d" " -f1 | tr -d '\n' | tail -n 1`
  12. fi
  13. echo $mem
  14. }
  15.  
  16. while [ 1 ]; do
  17. if [ -e /tmp/resetgnome ]; then
  18. rm -f /tmp/resetgnome
  19. dbus-send --type=method_call --print-reply --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval string:'global.reexec_self()'
  20. fi
  21. sleep 1
  22. done &
  23.  
  24. while [ 1 ]; do
  25. mem=$(getmem)
  26. echo MEM=$mem
  27. if [ $mem -gt $MAXMEM_1 ]; then
  28. echo "time to reset gnome-shell"
  29. while [ 1 ]; do
  30. mem=$(getmem)
  31. idle=`export DISPLAY=:1; xprintidle`
  32. echo "IDLE: $idle MEM: $mem"
  33. if [ $idle -gt $IDLE ] || [ $mem -gt $MAXMEM_2 ]; then
  34. wk=0
  35. d=`date +'%s'`
  36. if [ -f /tmp/woke ]; then
  37. wk=`cat /tmp/woke`
  38. fi
  39. r=$(($d-$wk))
  40. if [ $r -gt 60 ]; then
  41. export DISPLAY=:1
  42. touch /tmp/resetgnome
  43. break
  44. else
  45. echo "resumed recently"
  46. fi
  47. fi
  48. sleep 1
  49. export DISPLAY=:1
  50. fixgamma
  51. done
  52. fi
  53. export DISPLAY=:1
  54. fixgamma
  55. sleep 3
  56. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement