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

The Archive Base Latest Questions

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

I got some code that prints to stdout, in pseudo code it looks like

  • 0

I got some code that prints to stdout, in pseudo code it looks like

int main(){
    //allocate data
    while(conditional){
      char *string = makedata();
      fprintf(stdout,"%s",string);
    }
    //cleanup 
}

This works fine, if the conditional is toggled to zero, but if I pipe the output like

./a.out |head -n10 >dumped

Then the code never reaches the cleanup part, I don’t understand how to check if the stdout gets closed.

Thanks

  • 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-27T01:48:31+00:00Added an answer on May 27, 2026 at 1:48 am

    Your stdout hasn’t been closed, so checking for that will be useless. Your program has received a SIGPIPE and exited. A SIGPIPE is delivered whenever your program writes to a pipe on which there are no readers. In your example, that happens when head exits, closing its stdin.

    You should ignore SIGPIPE if you want your program to continue. This code will ignore SIGPIPE:

    (void)signal(SIGPIPE, SIG_IGN);
    

    If you don’t want to modify your program, you can arrange that something continues to read from the pipe, even after head closes its input. 1

    ./a.out | ( head -n10 >dumped ; cat > /dev/null )
    

    1: The shell example is valid for bash, maybe not for csh.

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

Sidebar

Related Questions

I've got some code that looks like this: using (DBDataContext dc = new DBDataContext(ConnectionString))
I've got some code that looks like this. The values of select#member_id get added
I've got some Python code that will automatically print a set of data in
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
We've got some code that uses LoadLibrary and GetProcAddress to implement a plugin architecture
I've got some code that uses the Component Categories manager to load all of
I've got some code that will generically get all Controls in a form and
I've got some code that was at the bottom of a php file that
I've got some code that lies in a browser, and wrote C++ plugins for
I've got some code that runs all lovely on SQL Server 2008, however I'm

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.