GNU Parallel is bundled with sem which is according to man is alias to parallel --semaphore. It limits number of simultaneously running processes.

man sem is pretty simple but full of details and toilet analogies. Complex stuff could be bundled to function.

#!/usr/bin/env bash

myproc() {
    local arg="$1"
    echo "$(date) >>> myproc arg=$arg"
    sleep "$arg"
    echo "$(date) <<< myproc arg=$arg"
}
export -f myproc

for i in $(seq 10 1); do
    sem -j4 myproc "$i"
done
sem --wait

TADAM!

Sat Jul 30 22:41:19 PDT 2022 >>> myproc arg=7
Sat Jul 30 22:41:26 PDT 2022 <<< myproc arg=7
Sat Jul 30 22:41:19 PDT 2022 >>> myproc arg=8
Sat Jul 30 22:41:27 PDT 2022 <<< myproc arg=8
Sat Jul 30 22:41:19 PDT 2022 >>> myproc arg=9
Sat Jul 30 22:41:28 PDT 2022 <<< myproc arg=9
Sat Jul 30 22:41:19 PDT 2022 >>> myproc arg=10
Sat Jul 30 22:41:29 PDT 2022 <<< myproc arg=10
Sat Jul 30 22:41:29 PDT 2022 >>> myproc arg=3
Sat Jul 30 22:41:32 PDT 2022 <<< myproc arg=3
Sat Jul 30 22:41:28 PDT 2022 >>> myproc arg=4
Sat Jul 30 22:41:32 PDT 2022 <<< myproc arg=4
Sat Jul 30 22:41:27 PDT 2022 >>> myproc arg=5
Sat Jul 30 22:41:32 PDT 2022 <<< myproc arg=5
Sat Jul 30 22:41:27 PDT 2022 >>> myproc arg=6
Sat Jul 30 22:41:33 PDT 2022 <<< myproc arg=6
Sat Jul 30 22:41:33 PDT 2022 >>> myproc arg=1
Sat Jul 30 22:41:34 PDT 2022 <<< myproc arg=1
Sat Jul 30 22:41:33 PDT 2022 >>> myproc arg=2
Sat Jul 30 22:41:35 PDT 2022 <<< myproc arg=2