[CODE]
/**
* Date : 2005. 11. 14
*
* Synopsis :
* Parent
* |
* +--+--+
* | |
* Child1 Child2
*
*
* Child2 -> Chlid1 -> Parent 로 메시지 전달
*
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main(void) {
int fd[2], fd2[2];
pid_t pid, pid2;
char line[255], line2[255];
int n;
if ( pipe(fd) < 0 || pipe(fd2) < 0 )
fprintf (stderr, "Error Pid!
");
if ( (pid = fork()) < 0 || (pid2 = fork()) < 0 )
fprintf (stderr, "Fork Error
");
else if ( pid > 0 ) {
close (fd[0]);
write (fd[1], "Hello, world!
", 14);
}
else if ( pid2 > 0) {
close (fd[1]);
read (fd[0], line2, 14);
write (fd2[1], line2, 14);
}
else {
close (fd2[1]);
n = read (fd2[0], line, 14);
line[n] = '?';
fprintf(stderr, "Chlid : %d %s
", n, line);
}
return 0;
}
[/CODE]