[ ECLiPSe Operating System built-in.|Group Index| Full Index]

wait(?Pid, ?Status)

Wait for a child process to terminate and report its process ID and status.

?Pid
Integer or variable
?Status
Integer or variable

Description

This predicate is an interface to the UNIX system call wait(2). The ECLiPSe process waits until a child process created by exec/3 or in some other way terminates or stops. Then Pid is unified with the process ID of that child process and Status with its exit status. If Pid does not unify with the process ID of the terminated child process the predicate backtracks and waits for another child process as long as there are some.

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.

Fail Conditions

Pid does not unify with the process ID of a terminated child process or Status does not unify with its exit status. Therefore it also fails if there are no child processes.

Resatisfiable

Yes.

Exceptions

(5) Type error
Pid or Status are instantiated to non-integers.
(170)
The ECLiPSe process received a signal while waiting.

Examples


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]:



See Also

exec / 2, exec / 3, exec_group / 3, kill / 2, sh / 1