Skip to content

Instantly share code, notes, and snippets.

@MiniXC
Last active March 19, 2024 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiniXC/47100a896d0d265aeb589b292919d744 to your computer and use it in GitHub Desktop.
Save MiniXC/47100a896d0d265aeb589b292919d744 to your computer and use it in GitHub Desktop.
ram_police.sh
if [ $# -eq 0 ]; then
tmux new-session -d -s ram_police
tmux send-keys -t ram_police "bash ram_police.sh true" ENTER
tmux capture-pane -t ram_police
else
free_ram=$(free -g | grep -m1 -E "[[:digit:]]" | tail -c4)
ram_limit=10
clear
echo "RAM POLICE WITH $ram_limit GB MIN."
# check if availabe RAM is below the limit every second
# do nothing if RAM is above the limit
# kill all python processes if RAM is below the limit
police="πŸ”΄πŸ”΅"
while true; do
current_date_time=$(date)
if [ $free_ram -lt $ram_limit ]; then
echo "[${current_date_time}] πŸš“ RAM is almost full"
echo "[${current_date_time}] πŸ”ͺ python processes"
pkill -f .*python.*
free_ram=$(free -g | grep -m1 -E "[[:digit:]]" | tail -c4)
else
if [ $police == "πŸ”΄πŸ”΅" ]; then
police="πŸ”΅πŸ”΄"
else
police="πŸ”΄πŸ”΅"
fi
echo -ne "[${current_date_time}] $police $free_ram GB RAM free $police\033[0K\r"
free_ram=$(free -g | grep -m1 -E "[[:digit:]]" | tail -c4)
fi
sleep 1
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment