Please cut down the context a bit more next time, it makes it much
easier to find your review.
On Mon, 2026-06-29 at 01:10 +0800, Wen Yang wrote:
> On 6/25/26 20:14, Gabriele Monaco wrote:
> > + eval "$TIMEOUT" "$command" &> check_output.$$ &
> > + bgpid=$!
> > + pid=$(pgrep -f "${command%%[|;&>]*}" | tail -n1)
>
> The pgrep runs may immediately after the background fork, before the
> child process has had time to exec.
Yeah I'm aware of this but kind of ignored it for now and never seen it
making troubles in practice..
I could add some delay waiting for the task like:
while [ -z "$pid" ]; do
sleep .5
pid=$(pgrep -f "${command%%[|;&>]*}" | tail -n1)
done
With probably a maximum of some N retrials in case the task never
started or we messed up the pattern.
That may still race in case the command exits before we pgrep it, but in
practice that shouldn't be a problem in our tests.
Any better idea? We cannot really rely on the shell's $! because command
is using a combination of eval+timer and we'd get the wrong pid.
Thanks,
Gabriele