Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created Mar 19, 2015
Embed
What would you like to do?
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