3 #include <sys/wait.h> /* for waitpid() macros */
13 /* Initiate pipe stream to ``du'' */
14 fp
= popen("du", "r");
20 /* Read from stream */
21 while (fgets(str
, MAX_STR
, fp
) != NULL
) {
25 /* Close pipe stream */
33 * Use macros described under wait() to inspect the return value
34 * of pclose() in order to determine success/failure of command
35 * executed by popen().
39 printf("Child exited, ret = %d\n", WEXITSTATUS(ret
));
40 } else if (WIFSIGNALED(ret
)) {
41 printf("Child killed, signal %d\n", WTERMSIG(ret
));
42 } else if (WIFSTOPPED(ret
)) {
43 printf("Child stopped, signal %d\n", WSTOPSIG(ret
));
45 /* Not all implementations support this */
47 else if (WIFCONTINUED(ret
)) {
48 printf("Child continued\n");
51 /* Non standard case -- may never happen */
53 printf("Unexpected return value, ret = 0x%x\n", ret
);