santiago revisou este gist . Ir para a revisão
1 file changed, 39 insertions
are_games_running.sh(arquivo criado)
| @@ -0,0 +1,39 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | set -euo pipefail | |
| 3 | + | ||
| 4 | + | POWER_LIMIT=30 | |
| 5 | + | ||
| 6 | + | power="$(nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits 2>/dev/null | head -n1)" | |
| 7 | + | ||
| 8 | + | if [[ -z "$power" ]]; then | |
| 9 | + | echo "OOPS: cannot read GPU power - check nvidia GPU driver" | |
| 10 | + | exit 1 | |
| 11 | + | fi | |
| 12 | + | ||
| 13 | + | ||
| 14 | + | # Numeric compare (decimal-safe) | |
| 15 | + | if awk -v p="$power" -v t="$POWER_LIMIT" 'BEGIN { exit !(p < t) }'; then | |
| 16 | + | echo "Ignoring low GPU power ${power} W < ${POWER_LIMIT} W" | |
| 17 | + | exit 1 | |
| 18 | + | else | |
| 19 | + | echo "GPU Power is $power W -- above idle limit ($POWER_LIMIT W)" | |
| 20 | + | fi | |
| 21 | + | ||
| 22 | + | # protect process containing one of these strings | |
| 23 | + | NOT_GAMES=( | |
| 24 | + | blender | |
| 25 | + | dontkillme | |
| 26 | + | ) | |
| 27 | + | ||
| 28 | + | for s in "${NOT_GAMES[@]}"; do | |
| 29 | + | if ps -eo args \ | |
| 30 | + | | grep -qi -- "$s" \ | |
| 31 | + | | grep -qv grep; then | |
| 32 | + | echo "PROTECTED process matched, exiting '$s'" | |
| 33 | + | exit 1 | |
| 34 | + | fi | |
| 35 | + | done | |
| 36 | + | ||
| 37 | + | ||
| 38 | + | echo "Games likely running with GPU ${power}W" | |
| 39 | + | exit 0 | |
Próximo
Anterior