3

私は非常に最初のパイプ作業を取得しようとしています: 基本的に、入力した内容を画面に表示するプログラムを作成しました。 . 私のコードは次のとおりです。

if ( pid > 0 ) //If I'm the parent
{
    close(fd[0]);
    //as long as something is typed in and that something isn't 
    // the word "stop"
    while (((n = read(STDIN_FILENO, buffer, BUFFERSIZE)) > 0) && 
           (strncmp(buffer, "stop", 4) != 0))
    {
        //shove all the buffer content into the pipe
        write(fd[1], buffer, n);
    }

}
else //If I am the child
{
    close(fd[1]);

    //as long as there's something to read
    while (pipe_read = read(fd[0], buf, BUFFERSIZE) > 0)
    {
        //display on the screen!
        write(STDOUT_FILENO, buf, pipe_read);
    }

}
4

1 に答える 1