[ Operating System | The ECLiPSe Built-In Predicates | Reference Manual | Alphabetic 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 used to make the ECLiPSe process wait 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.

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.

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) system interface error
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