Guest User

Untitled

a guest
Feb 23rd, 2018
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 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. touch /tmp/resetgnome
  37. break
  38. fi
  39. sleep 1
  40. done
  41. fi
  42. sleep 3
  43. done
Advertisement
Add Comment
Please, Sign In to add comment