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

  • Home
  • SEARCH
  • 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 769017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:16:15+00:00 2026-05-14T18:16:15+00:00

I’m doing a course in Operating Systems and we’re supposed to learn how to

  • 0

I’m doing a course in Operating Systems and we’re supposed to learn how to use pipes to transfer data between processes.

We were given this simple piece of code which demonstrates how to use pipes,but I’m having difficulty understanding it.

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

main()
{
      int  pipefd [2], n;
      char buff[100] ;


      if( pipe( pipefd) < 0)
      {
        printf("can not create pipe \n");
      }
      printf("read fd = %d, write fd = %d \n", pipefd[0], pipefd[1]);
      if ( write (pipefd[1],"hello world\n", 12)!= 12)
      {
        printf("pipe write error \n");
      }
      if(  ( n = read ( pipefd[0] , buff, sizeof ( buff)  ) ) <= 0 )
      {
        printf("pipe read error \n");
      }
      write ( 1, buff, n ) ;
exit (0);
  }

What does the write function do? It seems to send data to the pipe and also print it to the screen (at least it seems like the second time the write function is called it does this).

Does anyone have any suggestions of good websites for learning about topics such as this, FIFO, signals, other basic linux commands used in C?

  • 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-14T18:16:16+00:00Added an answer on May 14, 2026 at 6:16 pm

    The function creates a pipe and stores its endpoing file descriptors in pipefd[0] and pipefd[1]. Anything you write to one end can be read from the other and vice versa. The first write() call writes “hello world” to pipefd[1], and the read() call reads that same data from pipefd[0]. Then, the second write() call writes that data to file descriptor 1, which is STDOUT by default, which is why you see it on the screen.

    Pipes can be confusing at first. As you read / write more code that use them, they’ll become much easier to understand. I recommend W. Richard Stevens Advanced Programming in the UNIX Environment as a good book to understand them. As I recall, it has good code examples.

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

Sidebar

Related Questions

No related questions found

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.