diff --git a/src/subconscious/agents/bail-no-competing.sh b/src/subconscious/agents/bail-no-competing.sh index 3f39057..43c3096 100755 --- a/src/subconscious/agents/bail-no-competing.sh +++ b/src/subconscious/agents/bail-no-competing.sh @@ -10,7 +10,13 @@ shopt -s nullglob my_pid_file="$1" for f in pid-*; do - [[ $f != $my_pid_file ]] && exit 1 + [[ $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