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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:44:57+00:00 2026-05-30T01:44:57+00:00

Yes, I can’t. It seems weird ostream has no close, since istream can detect

  • 0

Yes, I can’t. It seems weird ostream has no close, since istream can detect end of file.

Here’s my situation: I am capturing all the output on Posix fd2, in this process, and its children, by creating a pipe and dup2’ing the pipe output end onto fd2. A thread then reads the read end of the pipe using an associated C stream (and happens to write each line with a timestamp to the original fd2 via another associated C stream).

When all the children are dead, I write a closing message to cerr, then I need to close it so the thread echoing it to the original error file will close the pipe and terminate.

The thread is not detecting eof(), even though I am closing both stderr and fd2.

I have duplicated my main program using a simple one, and using C streams instead of C++ iostreams, and everything works just fine by fclosing stderr (there are no child processes in that simplified test though).

Edit: hmm .. do I need to close the original pipe fd after dup2’ing it onto channel 2? I didn’t do that, so the underlying pipe still has an open fd attached. Aha .. that’s the answer!

  • 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-30T01:44:58+00:00Added an answer on May 30, 2026 at 1:44 am

    When you duplicate a file descriptor with dup2 the original descriptor remains a valid reference to the underlying file. The file won’t be closed and the associated resources freed until all file descriptors associated with a particular file are closed (with close).

    If you are using dup2 to copy a file descriptor to a well known number (such as 2 for stderr), you usually want to call close on the original file descriptor immediately after a successful dup2.

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

Sidebar

Related Questions

I have to encrypt/decrypt some sensitive information in a Xml file? Yes I can
Has anyone implemnted the stackoveflow/digg like voting system using JSP/Servlet/Java technology? If yes can
can I use .net framework 4.0 in VS2008 ? If yes how can I
yes what returned can be formatted using HH to display value in 24hrs, but
(Yes I know I can call Java code from Scala; but that is pointless;
I can't find a straightforward yes or no answer to this! I know I
How can i only output that yes or no by skiping anything? $ pactl
Yes, I know that downcast using dynamic_cast can't compile if the Base is not
Can Silverlight 3 OPEN SOCKETS? If yes. What do I need MSDN if there
Can the application use set same char in the XON and XOFF? If yes,

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.