Advertisement
Guest User

Untitled

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