6 /* Read characters from the pipe and echo them to @code{stdout}. */
9 read_from_pipe (int file
)
13 stream
= fdopen (file
, "r");
14 while ((c
= fgetc (stream
)) != EOF
)
19 /* Write some random text to the pipe. */
22 write_to_pipe (int file
)
25 stream
= fdopen (file
, "w");
26 fprintf (stream
, "hello, world!\n");
27 fprintf (stream
, "goodbye, world!\n");
38 /* Create the pipe. */
41 fprintf (stderr
, "Pipe failed.\n");
46 /* Create the child process. */
50 /* This is the child process. */
51 read_from_pipe (mypipe
[0]);
54 else if (pid
< (pid_t
) 0)
56 /* The fork failed. */
57 fprintf (stderr
, "Fork failed.\n");
62 /* This is the parent process. */
63 write_to_pipe (mypipe
[1]);