Its for only 3 processes :-
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#define MSGSIZE 14
char *message = "hello, world!";
main() {
char inbuf[MSGSIZE];
int p[3];
pid_t pid;
pid_t pid1;
if (pipe(p) == -1){
perror("pipe call");
exit(1);
}
pid = fork();
pid1 = fork();
if(pid == -1){
perror("Fork failed");
exit(1);
}
if(pid | pid1 == 0)
{
close(p[0]);
write(p[1], message, MSGSIZE);
read(p[1], message, MSGSIZE);
write(p[2], message, MSGSIZE);
}
else{
close(p[2]);
read(p[0], inbuf, MSGSIZE);
printf("Pipelined message return:%s\n", inbuf);
wait(NULL);
}
exit(0);
}