정보교환 - 해당되는 글 1건

#include <stdio.h>
#include <unistd.h>
#define SIZE 4

main()
{
    char *arg[3] = {"abc", "def", "ghi"};
    char buffer[SIZE];
    int pipes[2], i;

    /* 파이프 생성 */
    if(pipe(pipes) == -1) {
       perror("pipe failed");
       exit(1);
    }

    /* 자식 프로세스를 생성하고 부모 프로세스는 */
    if(fork()) {
       for(i=0; i<3; i++) {
          /* 파이프에 arg[i]를 쓰기 */
          write(pipes[1], arg[i], SIZE);
          printf("parent process write to pipe: %s\n", arg[i]);
       }
    /* 자식 프로세스는 */
    } else {
       for(i=0; i<3; i++) {
          /* 파이프로부터 읽기 */
          read(pipes[0], buffer, SIZE);
          printf("child process read from pipe: %s\n", buffer);
       }
    }
    exit(0);
}

//자식프로세르를 만들어서 부모프로세스와의 정보를 교환
25-11도 그런예제
코드영역은 공유를 하고, 전역 변수같은 부분은 공유할 부분은 공유하고 복사할부분은 복사
변수를 복사를 한다.

      c 언어  |  2007. 9. 17. 12:09



sokoban's Blog is powered by Daum & Tattertools