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 Close other end first. */
53 read_from_pipe (mypipe
[0]);
56 else if (pid
< (pid_t
) 0)
58 /* The fork failed. */
59 fprintf (stderr
, "Fork failed.\n");
64 /* This is the parent process.
65 Close other end first. */
67 write_to_pipe (mypipe
[1]);