Skip to content

Conversation

@yashaswi2000
Copy link

This PR addresses an issue where the output from a program using the fork() system call was duplicated, resulting in unintended output. The problem was due to both the parent and child processes having the same iO buffers causing both to print to the standard output.

To resolve this, the following changes were made:

  • Added fflush(stdout); before the fork() call to ensure that the buffer is flushed, preventing any buffered output from being duplicated in the child process.

  • With these changes, the program now produces the correct and intended output, ensuring only the parent process prints "2!" while the child process exits immediately.

Issue link: Lind-Project/native_client#12

Copy link
Member

@JustinCappos JustinCappos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this problem only exist for stdout / stderr? What if they are duped to new fds? Do those need to be flushed as well / intead? What if stdout and stderr are redirected to new types of output (not the terminal)?

Can we add some tests for these cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants