Thursday, September 6, 2012

fork


kthread
create_kthread
kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);

sys_fork(wrapper)
do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);

sys_clone(wrapper)
do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);

sys_vfork(wrapper)
do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);

COW is used in Fork.
Parent and child share the same memory regions.
once write occurs both child and parent gets its own memory regions.

vfork -> share the address space.
parent is suspended till child exits.
what happens after exec on vfork?
1. New address space is created for both parent & child. If so , does parent wait for child to exit.
2. both will be executing with new address space.?

 Because parent and child share the address space, you must not return from the function that called vfork(); doing so can corrupt the parent's stack..
 if your exec() call fails, you must call  __exit() , and not exit(), because calling exit() would close standard I/O stream buffers for the parent as well as the child.

No comments:

Post a Comment