nullpointer wrote: ↑Wed Jan 07, 2026 1:01 pm
Hi all,
I couldn't understand what's the problem of user stack when task0 forks task1 in linux 0.01.
Why this problem don't occur when task1 forks task2 ?!
Thanks for help.
I'm not sure what problem you're referring to.
But, I wonder if task0 doesn't have a user stack when it forks? task0 will be the bootstrap thread, with no user context yet, and task1 will be the first user process that runs init. In UNIX, task0 (pid 0) ends up being the scheduler process, which swaps process to and from disk, and remains in kernel mode always.
In which case, that first fork will be of a limited kernel only context, and the user context will have to be crafted from scratch.
That's how my kernel works, at least.
Bootstrap thread forks pid 1, which has a special bootstrap routine to run the init process (mine calls execve to run /bin/init.)
Subsequent forks (descendants of pid 1 - init) will have a user context to fork, so the post fork kernel side routine just needs to arrange a return to the duplicated user context with a return value of 0, whereas the parent process will return the pid of the new process.