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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:44:10+00:00 2026-05-21T22:44:10+00:00

This is some pseudo code of what I’m trying to achieve: fork in the

  • 0

This is some pseudo code of what I’m trying to achieve:

fork

in the child, dup2 a output descriptor to a file then exec a different program

in parent, kill the child after a period of time

The problem is though that after I kill the child the output file is empty even though the child has written to it at some stage. What am I doing wrong? I don’t want to wait for the child but I also don’t want it to reverse what it’s already written to file.

  • 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-21T22:44:11+00:00Added an answer on May 21, 2026 at 10:44 pm

    If your child dies as a result of a signal, it won’t flush any buffers, that’s why you don’t see any output. There are solutions for this

    • Handle the signal and flush the buffers
    • Use unbuffered I/O (should avoid this)
    • Synchronize the child and the parent (using the pipe) (so that the parent knows it’s safe to kill the child).

    Of course, the third option is rather silly: the child signaling the parent could be replaced by simply exiting.

    Edit
    In light of edited question and comments

    stdio (printf, fwrite etc.), for reasons of I/O efficiency uses some buffers. That is, when you do a simple write, the low-level operation doesn’t happen right away. The data is copied to some buffer and later, when the library deems it necessary (full buffers or something else) the buffers will be flushed – stuff is going to be written.

    Now, when a program calls exit(3) (normal process termination) on of the things that happens is that stdio buffers are flushed. If a program dies as a result of a signal, stdio buffers aren’t flushed and the memory is simply claimed by the OS.

    If you don’t have control over the programs you exec (say you’re a shell) you can’t be sure they will do their thing if you kill them. That is, it’s not your responsibility. If however you do have control over them (you said something about a pipe) you can simply signal through the pipe some sequence that will make the children call exit(3).

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

Sidebar

Related Questions

Let me first explain what I'm trying to achieve using some pseudo-code (JavaScript). //
How can I solve this riddle programmatically? Could someone help me with some pseudo-code
I have a plain text file looking like this: some text containing line breaks
This is some code I found on the internet. I'm not sure how it
this is some code that SDL requires in visual studios 2005 in order for
In this thread some one commented that the following code should only be used
I just found this in some old code, and I'm not sure what it
Has anyone done this / have some example code?
I'm designing a method for an input handler class. Here is some pseudo code...
I'm not sure how to describe this, but I'll try with some basic code:

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.