Skip to content

add fork support, like linux kernel, every process has one freebsd struct thread #887

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

Merged

Conversation

liujinhui-job
Copy link
Contributor

The current fork implementation has an issue: after creating a socket and invoking fork, both the parent and child processes call close. When the parent process closes the socket, it is released immediately. Subsequently, when the child process attempts to close it, the file descriptor (fd) no longer exists. This behavior differs significantly from Linux, which can lead to various problems. In a true Linux implementation:

Child processes ‌inherit‌ open file descriptors from the parent upon fork, meaning the reference count of the file is incremented.
Each process in Linux corresponds to a task_struct.

The purpose of this commit is to ‌simulate Linux's behavior‌ by addressing these two aspects.

The partial reason has been explained in my CSDN blog:
https://blog.csdn.net/weixin_41607301/article/details/146396412?spm=1001.2014.3001.5502

@jfb8856606 jfb8856606 merged commit 2869cbf into F-Stack:dev May 23, 2025
1 check passed
@liujinhui-job liujinhui-job deleted the add-new-fork-implementation-method branch June 8, 2025 15:41
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