pclose - close a pipe stream to or from a process
#include <stdio.h> int pclose(FILE *stream);
The pclose() function closes a stream that was opened by popen(), waits for the command to terminate, and returns the termination status of the process that was running the command language interpreter. However, if a call caused the termination status to be unavailable to pclose(), then pclose() returns -1 with errno set to [ECHILD] to report this situation; this can happen if the application calls one of the following functions:
- waitpid() with a pid argument less than or equal to 0 or equal to the process ID of the command line interpreter
- any other function not defined in this specification that could do one of the above.
In any case, pclose() will not return before the child process created by popen() has terminated.
If the command language interpreter cannot be executed, the child termination status returned by pclose() will be as if the command language interpreter terminated using exit(127) or _exit(127).
The pclose() function will not affect the termination status of any child of the calling process other than the one created by popen() for the associated stream.
If the argument stream to pclose() is not a pointer to a stream created by popen(), the result of pclose() is undefined.
Upon successful return, pclose() returns the termination status of the command language interpreter. Otherwise, pclose() returns -1 and sets errno to indicate the error.
The pclose() function will fail if:
- The status of the child process could not be obtained, as described above.
fork(), popen(), waitpid(), <stdio.h>.
Derived from Issue 1 of the SVID.