1
votes

When we call fork(). It call to system call clone which call to do_fork function and inside this function, it call copy_process. copy_process call dup_task_struct which creates new kernel stack, new task_struct, new thread_info for new process. and if exec called it create new process.

But when does user space stack created in this sequence of creating process? I have same question for thread.

Does user space stack also has pointer to task_struct or thread_info type of structure ?

Please help me out here and correct me if I asked something silly.

1

1 Answers

2
votes

in fork() , the user stack is not created. user stack is represented by vm_area_struct of mm_struct. do_fork call copy_mm, where it duplicate the new process mm_struct of the one that called fork only if CLONE_VM flag is not set. if set, in case of thread creation, its just increment the count of mm_user and new task mm points to the current task mm.

only when exec is called do_execve is invoked whic calls bprm_mm_init, allocate_mm is called which allocates from mm_cachep slab (of course memory is also needed to duplicate the mm for a new process ), and then mm_init initialize the mm struct and also alloc memory for the page global directory.

then a call to __bprm_mm_init creates the user space stack that is the vm_area_struct structure for the stack