Sample client application, with output
- The following client program and test run illustrate precisely how subprocess should work:
int main(int argc, char *argv[]) {
subprocess_t sp = subprocess("/usr/bin/sort");
const char *words[] = {
"felicity", "umbrage", "susurration", "halcyon",
"pulchritude", "ablution", "somnolent", "indefatigable"
};
for (size_t i = 0; i < sizeof(words)/sizeof(words[0]); i++) {
dprintf(sp.infd, "%s\n", words[i]);
}
close(sp.infd); // effectively sends cntl-D to child process
int status;
pid_t pid = waitpid(sp.pid, &status, 0);
return pid == sp.pid && WIFEXITED(status) ? WEXITSTATUS(status) : -1;
}
- The output of the above program, given a properly implemented subprocess routine, should look like so:
myth22> ./subprocess-test
ablution
felicity
halcyon
indefatigable
pulchritude
somnolent
susurration
umbrage