Skip to content

Instantly share code, notes, and snippets.

@rocallahan
Created August 25, 2016 04:35
Show Gist options
  • Save rocallahan/fec1dcd017d1bb3fcb5e29ba0ed70b15 to your computer and use it in GitHub Desktop.
Save rocallahan/fec1dcd017d1bb3fcb5e29ba0ed70b15 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <sys/wait.h>
#include <assert.h>
int main(void) {
int fds_to_child[2];
int fds_to_parent[2];
int i;
char ch = 'x';
int status;
pid_t child;
pipe(fds_to_child);
pipe(fds_to_parent);
child = fork();
if (!child) {
for (i = 0; i < 100000; ++i) {
read(fds_to_child[0], &ch, 1);
write(fds_to_parent[1], &ch, 1);
}
return 77;
}
for (i = 0; i < 100000; ++i) {
write(fds_to_child[1], &ch, 1);
read(fds_to_parent[0], &ch, 1);
}
wait(&status);
assert(WIFEXITED(status) && WEXITSTATUS(status) == 77);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment