task1 forking in Linux 0.01.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
nullpointer
Posts: 10
Joined: Sat Jun 29, 2019 8:58 am

task1 forking in Linux 0.01.

Post by nullpointer »

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.
thewrongchristian
Member
Member
Posts: 471
Joined: Tue Apr 03, 2018 2:44 am

Re: task1 forking in Linux 0.01.

Post by thewrongchristian »

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.
nullpointer
Posts: 10
Joined: Sat Jun 29, 2019 8:58 am

Re: task1 forking in Linux 0.01.

Post by nullpointer »

Thanks thewrongchristian for your reply.
thewrongchristian wrote: Wed Jan 07, 2026 5:18 pm I'm not sure what problem you're referring to.
here's what Linus wrote in init/main.c:
"forking from kernel space will result in NO COPY ON WRITE (!!!), until an execve is executed. This is no problem, but for the stack."

How using the user space stack by task0 before forking task1 creates a problem?
Post Reply