This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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