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 8339835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:59:30+00:00 2026-06-09T04:59:30+00:00

I have this following scenario. I create a pipe. Forked a child process. Child

  • 0

I have this following scenario.

  1. I create a pipe.

  2. Forked a child process.

  3. Child closes read end of the pipe explicitly and writes into the write end of the pipe and exits without closing anything ( exit should close all open file/pipe descriptors on behalf of the child, I presume).

  4. Parent closes the write end of the pipe explicitly and reads from the read end of the pipe using fgets until fgets returns NULL. ie it reads completely.

Now my question is, why does the parent need to close the read end of the pipe explicitly once its done reading? Isn’t it wise for the system to delete the pipe altogether once complete data has been read from the read-end?

I dint close the read end explicitly in the parent and I have Too many file descriptors error sooner or later while opening more pipes. My assumption was that the system automatically deletes a pipe once its write end is closed and data has been completely read from read end. Cos you cant from a pipe twice!

So, whats the rationale behind the system not deleting the pipe once data has been completely read and write end closed?

  • 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-06-09T04:59:31+00:00Added an answer on June 9, 2026 at 4:59 am

    You’re correct that the system will close the write end of the pipe once the child exits. However there could be another write end of that pipe open, if the child forks or passes a duplicate of the write end to another process.

    It is still true that the system would be able to tell when all the descriptors at one end of a pipe have been closed (either explicitly or because the owning process exited). It still doesn’t make sense to close those on the other end of the pipe, as that would lead to confusion when the parent process tries to close the descriptor on its end of the pipe; either:

    • the fd has been closed by the system, in which case there is an error as it tries to close an already closed fd; or
    • the fd has been reused, which is even worse as it is now closing a completely unrelated fd.

    From the point of view of the system, it might well have discarded the pipe once all the descriptors at one end have been closed, so you don’t need to worry about inefficiency there. What matters more is that the user space process should have a consistent experience, which means not closing the descriptor unless it is specifically requested.

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

Sidebar

Related Questions

Following on from this question...I'm trying to unit test the following scenario: I have
I have the following scenario. We have a sharepoint 2010 web template to create
Actually I have the following scenario: I want to create an app that will
this is my first time here... I have the following scenario: <div class=album-wrap> <img
I have been learning managed pointers lately and ran into the following scenario. I
I have this following codes: @implementation MyImageView @synthesize image; //image is a UIImage -
i have this following html structure usilg ul and li. <ul class=treeview id=productTree> <li
I have this following jquery text fly-in animation.Here is my code before I explain
I have this following query for CodeIgniter: $q = $this->db->where('(message_from='.$user_id.' AND message_to='.$this->auth_model->userdata['user_id'].')') ->or_where('(message_from='.$this->auth_model->userdata['user_id'].' AND
I have this following IEnumerable LINQ query: var query = from p in Enumerable.Range(2,

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.