If, at the moment of wait/2 invocation, there are already some child processes that exited and that were not reported by a previous wait/2 call, this predicate returns immediately, otherwise it blocks until a child exits or a signal is received.
On Windows, wait/2 can only wait for one specific process, i.e. the Pid argument must be instantiated and the predicate is not resatisfiable.
Note A child process created with exec/3 still exists in the operating system even after it exits as long as it was not waited for. Therefore it is advisable to use a wait/2 call after every exec/3, unless exec/3 waits itself for the child process.
Note (UNIX) If the child process created by exec/3 or exec_group/3 cannot be executed, the child exits with status 128 + errno.
Note (Windows) A process that was created using exec_group/3 cannot be waited for.
Success:
[eclipse]: exec("true", [], Pid), wait(P, Status).
Pid = 3417
P = 3417
Status = 0
yes.
[eclipse]: exec("false", [], Pid1),
exec("false", [], Pid2),
wait(P1, S1).
Pid1 = 10611
Pid2 = 10612
P1 = 10612
S1 = 256 More? (;)
Pid1 = 10611
Pid2 = 10612
P1 = 10611
S1 = 256 More? (;)
no (more) solution.
[eclipse]: exec("true", [], Pid), exec(date, [], Pid2),
wait(Pid2, S2).
Thu May 17 16:58:45 MET DST 1990
Pid = 10617
Pid2 = 10618
S2 = 0 More? (;)
no (more) solution.
Fail:
[eclipse]: exec("true", [], Pid), wait(1111, S).
no (more) solution.
Error:
[eclipse]: exec(bc, [], A), wait(P, S).
Signal 23 % sending a signal to this process
system interface error: Interrupted system call
in wait(_g50, _g42)
[eclipse]: