Skip to content

Instantly share code, notes, and snippets.

@claudemartin
Created April 3, 2017 07:24
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 claudemartin/000337e67e5a3507a548a6ce080fb64e to your computer and use it in GitHub Desktop.
Save claudemartin/000337e67e5a3507a548a6ce080fb64e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define MSGSIZE 16
char *msg1 = “hello, world #1”;
char *msg2 =“ hello, world #2”;
char *msg3 =“ hello, world #3”;
main () {
char inbuf[MSGSIZE];
int p[2], j, pid;
if (pipe (p) < 0) {
perror (“pipe call”);
exit (1); }
if ((pid = fork()) < 0) {
perror(“fork call”);
exit(2);
}
if (pid > 0) {
write(p[1], msg1, MSGSIZE);
write(p[1], msg2, MSGSIZE);
write(p[1], msg3, MSGSIZE);
wait((int * ) 0);
}
if (pid == 0) {
for (j = 0; j < 3; j++) {
read(p[0], inbuf, MSGSIZE);
printf(“ % s\ n”, inbuf);
}
}
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment