File size: 1,003 Bytes
a8d795a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #!/usr/bin/env bash
# Stop generation workers without matching the caller's own command line.
#
# Passing the pattern on an interactive command line makes pgrep match that very
# command, so the kill takes down the shell issuing it. Keeping the pattern
# inside a file, and excluding this script's own process tree, avoids that.
set -uo pipefail
self=$$
mine=$(ps -o ppid= -p "$self" | tr -d ' ')
kill_matching() {
local pattern=$1 signal=$2 pid
for pid in $(pgrep -f "$pattern"); do
[[ "$pid" == "$self" || "$pid" == "$mine" ]] && continue
kill "-$signal" "$pid" 2>/dev/null
done
}
kill_matching 'chain_sweep\.sh' TERM
kill_matching 'chain\.sh' TERM
kill_matching 'guarded_launch\.sh' TERM
kill_matching 'run_worker\.sh' TERM
sleep 3
kill_matching 'run_context_memory_lingbot_sp\.py' KILL
sleep 15
left=$(pgrep -cf 'run_context_memory_lingbot_sp\.py' || true)
echo "generation workers left: $((left > 1 ? left - 1 : 0))"
nvidia-smi --query-gpu=index,memory.used --format=csv,noheader
|