wait

From RAD Studio
Jump to: navigation, search

Go Up to process.h Index


Header File

process.h

Category

Process Control Routines

Prototype

int wait(int *statloc);

Description

Waits for one or more child processes to terminate.

The wait function waits for one or more child processes to terminate. The child processes must be those created by the calling program; wait cannot wait for grandchildren (processes spawned by child processes). If statloc is not NULL, it points to the location where wait will store the termination status, as returned by GETEXITCODEPROCESS.


Return Value

When wait returns after a normal child process termination it returns the process ID of the child.

When wait returns after an abnormal child termination it returns -1 to the parent and sets errno to EINTR.

If wait returns without a child process completion it returns a -1 value and sets errno to:

Errno Meaning

ECHILD

No child process exists

Example

#include <process.h>
#include <stdio.h>
int spawn_and_wait(wchar_t* program)
{
  /* Spawn another process with NOWAIT flag */
  int pid = _wspawnl(P_NOWAIT, program, NULL);
  int exitCode;

  /* Check for error */
  if (pid == -1)
    return -1;

  /* Wait for the any child processes to finish */
  wait(&exitCode);
  return exitCode;
}


Portability

POSIX Win32 ANSI C ANSI C++

+