consciousness/src/subconscious/agents/bail-no-competing.sh

22 lines
446 B
Bash
Raw Normal View History

#!/bin/bash
# Bail if other agents are alive in the state dir.
# $1 = this agent's pid file name (e.g. pid-12345)
# cwd = state dir
#
# Exit 0 = continue, exit 1 = bail
shopt -s nullglob
my_pid_file="$1"
for f in pid-*; do
2026-04-11 18:41:44 -04:00
[[ $f == $my_pid_file ]] && continue
pid="${f#pid-}"
if kill -0 "$pid" 2>/dev/null; then
exit 1 # competing agent is alive
else
rm -f "$f" # stale pid file, clean up
fi
done
exit 0