#!/bin/bash
# Is a process running, without the self-match that pgrep -f always has?
#   tools/flea-running "sleep 3600"     prints matching pids, exits 0 when there are any
#
# pgrep -f matches its own command line, and any shell that mentions the pattern, so it answers "yes"
# for a process that died minutes ago. It has done that three times on this project and once told the
# oversight session a benchmark was running when none had been for an hour. The handoff bans the
# shape; this exists so the correct form is the easy one to reach for.
set -u

# This tool reads machine output and launches no application for the user.
export LC_ALL=C.UTF-8
unset LANGUAGE

pattern=${1:-}
if [ -z "$pattern" ]; then
  echo "usage: flea-running <exact-command-line>" >&2
  exit 2
fi

. "$(dirname "$0")/../tests/lib/flea-transport.sh"
flea_test_running "$pattern"
