Coding/CPP 삽질기2005. 11. 14. 17:35
[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]

'Coding > CPP 삽질기' 카테고리의 다른 글

입력 버퍼비우기  (0) 2006.02.23
소수 구하기  (0) 2005.11.07
베이식 만들다...  (0) 2005.09.03
Posted by chobocho