Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6713803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:25:22+00:00 2026-05-26T08:25:22+00:00

Recently I started suspecting that I use the ends of the pipes wrongly: From

  • 0

Recently I started suspecting that I use the ends of the pipes wrongly:

From the man pages:

pipe() creates a pipe.. ..pipefd[0] refers to the read end of the
pipe. pipefd[1] refers to the write end of the pipe.

So in my mind I had it like this:

                .---------------------------.
               /                            /\
              | pipedfd[0]       pipedfd[1]|  |
process1 ---> |                            | -----> process2
              | input                output|  |
               \____________________________\/

However the code that I have here and works suggests otherwise:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{
  int pipedfd[2];
  char buf[30];

  pipe(pipedfd);
  printf("writing to file descriptor #%d\n", pipedfd[1]);
  write(pipedfd[1], "test", 5);
  printf("reading from file descriptor #%d\n", pipedfd[0]);
  read(pipedfd[0], buf, 5);
  printf("read \"%s\"\n", buf);

  return 0;
}

Namely it writes to the output(?) of the pipe and reads from the input(?) of the pipe?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:25:23+00:00Added an answer on May 26, 2026 at 8:25 am

    In a nutshell, swap the numbers 0 and 1 in your diagram and you got what I’ll describe below.

    From the Mac OS X man page:

    The pipe() function creates a pipe (an object that allows unidirectional data flow) and allocates a pair of file descriptors. The first descriptor connects to the read
    end of the pipe; the second connects to the write end.

    Data written to fildes[1] appears on (i.e., can be read from) fildes[0]. This allows the output of one program to be sent to another program: the source’s standard out-
    put is set up to be the write end of the pipe; the sink’s standard input is set up to be the read end of the pipe. The pipe itself persists until all of its associated
    descriptors are closed.

    I’ll describe how it’s often used, that might clear it up. Imagine you have a process and want to spawn a child, to which you want to send commands.

    • First, you call pipe and get the two file descriptors.
    • Then you call fork to create the child.
      • In the child, you close the writing file descriptor (fd[1]) and leave the reading one open.
      • In the parent, you do the reverse: you close the reading (fd[0]) file descriptor and leave the writing one open.
    • Now the parent can write into “his” part of the pipe (fd[1]) and the child can read on the other (fd[0]).

    The closing is not necessary but is usually done. If you need two-way communication you either need a second set of file descriptors plus a second call to pipe, or you use a two way channel like Unix domain sockets or a named pipe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started to learn how to use openCL to speed up some part
Recently started working with the scrapy library. I am trying to scrape from a
I recently started learning perl and have a question that I'm not finding a
I recently started a project where the team decided we'd like to use jQuery
I recently started using WPF and the MVVM framework, one thing that I have
I recently started to use the Nodewords module in Drupal 6. This adds the
I recently started using Linux as my primary OS. What are the tools that
I recently started with WCF ( yeah I know I am behind :-) ).
I recently started using lcov to visualize my code coverage. It's a great tool.
I recently started with the 'Agile web development with Rails' book by pragmatic programmers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.