Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR Summary: Fix Duplicate Output from fork() #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

2 participants