0

C の親プロセスから、それぞれプログラムを実行する 3 つの子プロセスを実行しています。

  • プログラム 1 は stdin (ユーザー入力) を取得し、それを stdout に出力します。
  • プログラム 2 は標準入力 (プログラム 1 から取得する必要があります) を取得し、それを変更して標準出力に出力します。
  • プログラム 3 は標準入力 (プログラム 2 から取得する必要があります) を取得し、それを変更して標準出力に出力します。

program3 の出力を取得していますが、プログラム 2 の変更は表示されません。

以下は、親からの関連コードです。

if((child1 = fork()) < 0){
    /*fatal*/
}
else if(child1 == 0){ //inside child 1
    dup2(pipe1[1], 1); //child 1 uses pipe1[1] for writing
    close(pipe1[0]);

    execl("program1.out", (char *)0);
}
else{
    if((child2 = fork()) <0){
        /*fatal*/
    }
    else if(child2 == 0){ //inside child 2
        close(pipe1[1]);
        dup2(pipe1[0], 0); //child2 uses pipe1[0] for reading
        dup2(pipe2[1], 1); //child2 uses pipe[1] for writing

        execl("program2.out", (char *)0);
    }
    else{
        if((child3 = fork()) <0){
            /*fatal*/
        }
        else if(child3 == 0){ //inside child 3
            close(pipe2[1]);
            close(pipe1[0]);

            execl("program3.out", (char *)0);
        }
        else{ //inside parent
            wait(NULL);
        }
    }   
}

プログラムは、読み取り/書き込みに fgets と printf を使用しています。

以前の質問を確認しましたが、何が間違っているのかわかりませんでした。何か案は?

4

1 に答える 1