Остання активність 1767277683

Check wattage of NVIDIA GPU returns 0 if above threshold of 30W

are_games_running.sh Неформатований
1#!/usr/bin/env bash
2set -euo pipefail
3
4POWER_LIMIT=30
5
6power="$(nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits 2>/dev/null | head -n1)"
7
8if [[ -z "$power" ]]; then
9 echo "OOPS: cannot read GPU power - check nvidia GPU driver"
10 exit 1
11fi
12
13
14# Numeric compare (decimal-safe)
15if 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
18else
19 echo "GPU Power is $power W -- above idle limit ($POWER_LIMIT W)"
20fi
21
22# protect process containing one of these strings
23NOT_GAMES=(
24 blender
25 dontkillme
26)
27
28for 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
35done
36
37
38echo "Games likely running with GPU ${power}W"
39exit 0
40