#!/usr/bin/env bash

./program-b &
pid_b=$!

./program-a1 &
pid_a=$!

wait -n -p finished_pid "$pid_a" "$pid_b"

if [[ "$finished_pid" == "$pid_a" ]]; then
    echo "A finished first"
elif [[ "$finished_pid" == "$pid_b" ]]; then
    echo "B finished first"
fi

wait "$pid_a" "$pid_b" 2>/dev/null
