wait

Gamma: Version 4.0
Prev |  | Next

# `wait`

`wait` -- waits for process exit status.

## Syntax

    wait (taskid?, options?)

## Arguments

`taskid`

  A process ID number. A value of `0` indicates any process.

`options`

  Wait option `WNOHANG` or `WUNTRACED`.

## Returns

One of three possibilities:

- A list of four items:

  1. The process ID.

  2. The process exit status (`WEXITSTATUS`), or `nil`.

  3. A termination signal (`WTERMSIG`) if the process exited due to a signal, or `nil`.

  4. A stopped signal (`WSTOPSIG`) if the process stopped due to a signal, or `nil`.

- `t` if the `WNOHANG` option had been set and there was a child with a status change.

- `nil` if there was a failure due to error.

## Description

This function combines and simplifies the C functions `wait` and `waitpid` in a single function. If `taskid` is provided, then the function acts as `waitpid`, and will not return until the given child task has died.

The `WNOHANG` option allows the calling process to continue if the status of specified child process is not immediately available. The `WUNTRACED` option allows the calling process to return if the child process has stopped and its status has not been reported. Both of these can be specified using the `OR` (`||`) operator.

## Example

Process 1:

        Gamma> child = fork();
        9089
        Gamma> 0
        Gamma> if (child > 0) wait(); else exit_program(5);

Process 2:

        Gamma> kill(9089,14);
        t
        Gamma>

Process 1:

        (9089 nil 14 nil)
        Gamma>

See the Handling Terminated Processes section of Common Functions for Any Program chapter in the Cogent Tools Demo and Tutorials book for an example of this function used in context.

## See Also

`fork`, `exec`

Prev | Home | Next
`system` | Up | Dynamic Loading

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.