Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created March 19, 2015 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lettergram/d82bba9fd4dd7a1f5c29 to your computer and use it in GitHub Desktop.
Save lettergram/d82bba9fd4dd7a1f5c29 to your computer and use it in GitHub Desktop.
int pfds[2];
int SIZE = 30;
char buf[SIZE];
char * msg = "This is a pipe example!";
/** Generates two pipe file descriptors **/
pipe(pfds);
/** writer **/
if (!fork()) {
printf(" CHILD: writing to pipe\n");
write(pfds[1], msg, SIZE);
printf(" CHILD: exiting\n");
/** reader **/
}else{
printf("PARENT: reading from pipe\n");
read(pfds[0], buf, SIZE);
printf("PARENT: read \"%s\"\n", buf);
wait(NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment