How to Join with child process?

Java and perl have a join feature that allows the main thread to block until a child thread is finished.

Is there a similar feature in (1) bash and (2) perl that will allow the main process to block until the child process is complete?

Thanks,
Siegfried

in bash at least it is "wait"
You can wait for jobs, pids or all children.

Perl no doubt has something similar

Let us say I want to create five child processes while the parent process waits until they are all done.
(1) Normally I create a child process with the "&". How do I get the pid? Do I have to parse the "ps" command with perl or awk?
(2) How do I specify multiple child processes? I tried "info wait" and "man wait" with no luck. I also tried "info bash" and "man bash" and still no luck. However, I see that my distro does implement wait. Apparently it takes a single integer.

I tried "sleep 40&" and "sleep 30&" and "ps" and "wait 6088 5966" and that almost worked. It came back and said "pid 5956 is not a child of this shell after waiting for 6088". I'm checking my work. wait wants the first column of ps labeled "PID", correct?

Sieg

foo &
fooPID="${!}"
echo "foo's pid -> [${fooPID}]"

correct. Get the pid's of your background processes as outlined above and pass them to 'wait'.

Since my info/man pages are incomplete, I am assuming wait implements a logical "AND" allowing my parent process to sleep until all the children have died.

(1) How would I implement an "OR" wait where the parent waits for the first child to die, examine the return status code of that child, and possibly spawn a new child to take its place?

The children will all be running perl.

(2a) I've tried writing synchronous perl children use various integer values for exit function, but I cannot figure out how to detect the exit values in bash. How is this done for a synchronous child?

(2b) How do I detect the return status code for an asynchronous child when the parent is blocking on multiple children wait for the first to die?

Thanks much!
Siegfried