Re: Porting vfork()

Linus Torvalds (torvalds@transmeta.com)
Wed, 6 Jan 1999 15:29:44 -0800 (PST)


On Wed, 6 Jan 1999, Perry Harrington wrote:
>
> I think that the traditional sense of vfork() is more akin to the clone() call
> with all of the special "hide me in my parents PID" options turned off.
> Perhaps vfork() should simply be an alias to clone() with the appropriate flags
> set?

It _should_ be reasonably straightforward to do vfork() by using clone().
It would go something like this:

Add the field

struct wait_queue *sleep;

to "struct mm_struct" in include/linux/sched.h. Add the code to initialize
it

init_waitqueue(&mm->sleep);

in mm_alloc() in kernel/fork.c, and then in kernel/fork.c: mmput() you'd
add a

wake_up(&mm->sleep);

at the top of the function.

Finally, add the following system call to arch/i386/kernel/process.c:

asmlinkage int sys_vfork(struct pt_regs regs)
{
/*
* This only works for a traditional process: don't
* try to do recursive vforks or mix clone and vfork.
*/
if (current->mm->count != 1)
return -EINVAL;

child = do_fork(CLONE_VM | SIGCHLD, regs.esp, &regs);
if (child > 0) {
while (current->mm->count > 1)
sleep_on(current->mm->sleep);
}
return child;
}

And you're done. Maybe. Apart from debugging the thing.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/