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.
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 If the child process created by exec/3 or exec_group/3 cannot be executed, the child exits with status 128 + errno.
WARNING: On some System V machines wait/2 might yield unexpected results due to unidentified problems in the system.
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]: