RAD Studio
ContentsIndex
PreviousUpNext
cwait

Header File 

process.h 

Category 

Process Control Routines 

Prototype 

int cwait(int *statloc, int pid, int action); 

Description 

Waits for child process to terminate. 

The cwait function waits for a child process to terminate. The process ID of the child to wait for is pid. If statloc is not NULL, it points to the location where cwait will store the termination status. The action specifies whether to wait for the process alone, or for the process and all of its children. 

If the child process terminated normally (by calling exit, or returning from main), the termination status word is defined as follows:

Bits 0-7 
Zero 
Bits 8-15 
The least significant byte of the return code from the child process. This is the value that is passed to exit, or is returned from main. If the child process simply exited from main without returning a value, this value will be unpredictable. 

If the child process terminated abnormally, the termination status word is defined as follows: 

Bits 0-7Termination information about the child:

 
Critical error abort. 
 
Execution fault, protection exception. 
 
External termination signal. 
Bits 8-15 
Zero 
 

 

Bits 8-15 
Zero 

If pid is 0, cwait waits for any child process to terminate. Otherwise, pid specifies the process ID of the process to wait for; this value must have been obtained by an earlier call to an asynchronous spawn function. 

The acceptable values for action are WAIT_CHILD, which waits for the specified child only, and WAIT_GRANDCHILD, which waits for the specified child and all of its children. These two values are defined in process.h. 

Return Value 

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

When cwait returns after an abnormal child termination, it returns -1 to the parent and sets errno to EINTR (the child process terminated abnormally). 

If cwait returns without a child process completion, it returns a -1 value and sets errno to one of the following values:

ECHILD 
No child exists or the pid value is bad 
EINVAL 
A bad action value was specified 

Portability

POSIX 
Win32 
ANSI C 
ANSI C++ 
 
 
 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!