// C program to illustrate
// pipe system call in C
#include <stdio.h>
#include <unistd.h>
#define MSGSIZE 16
char* msg1 = "hello, world #1";
char* msg2 = "hello, world #2";
char* msg3 = "hello, world #3";
int main()
{
char inbuf[MSGSIZE];
int p[2], i;
if (pipe(p) < 0)
/* continued */
/* write pipe */
write(p[1], msg1, MSGSIZE);
write(p[1], msg2, MSGSIZE);
write(p[1], msg3, MSGSIZE);
for (i = 0; i < 3; i++) {
/* read pipe */
read(p[0], inbuf, MSGSIZE);
}
return 0;
}
Ly8gQyBwcm9ncmFtIHRvIGlsbHVzdHJhdGUgCi8vIHBpcGUgc3lzdGVtIGNhbGwgaW4gQyAKI2luY2x1ZGUgPHN0ZGlvLmg+IAojaW5jbHVkZSA8dW5pc3RkLmg+IAojZGVmaW5lIE1TR1NJWkUgMTYgCmNoYXIqIG1zZzEgPSAiaGVsbG8sIHdvcmxkICMxIjsgCmNoYXIqIG1zZzIgPSAiaGVsbG8sIHdvcmxkICMyIjsgCmNoYXIqIG1zZzMgPSAiaGVsbG8sIHdvcmxkICMzIjsgCgppbnQgbWFpbigpIAp7IAoJY2hhciBpbmJ1ZltNU0dTSVpFXTsgCglpbnQgcFsyXSwgaTsgCgoJaWYgKHBpcGUocCkgPCAwKSAKCQlleGl0KDEpOyAKCgkvKiBjb250aW51ZWQgKi8KCS8qIHdyaXRlIHBpcGUgKi8KCgl3cml0ZShwWzFdLCBtc2cxLCBNU0dTSVpFKTsgCgl3cml0ZShwWzFdLCBtc2cyLCBNU0dTSVpFKTsgCgl3cml0ZShwWzFdLCBtc2czLCBNU0dTSVpFKTsgCgoJZm9yIChpID0gMDsgaSA8IDM7IGkrKykgeyAKCQkvKiByZWFkIHBpcGUgKi8KCQlyZWFkKHBbMF0sIGluYnVmLCBNU0dTSVpFKTsgCgkJcHJpbnRmKCIlIHNcbiIsIGluYnVmKTsgCgl9IAoJcmV0dXJuIDA7IAp9IAo=