From: Jones Syue
> Sent: 11 December 2023 07:59
>
> After digging further into textbook APUE 2/e and TLPI in this weekend,
> it looks like more clear to explain what is happening.
> In vfork() implementation,
> 1. The process address space is shared among parent and child processes.
> The process address space, including data, stack, and heap, which means any
> modification to a static variable (in data segment) is visible to others.
> That's why vfork() is much faster and less memory footprint than fork(),
> which is very efficient for entry-level cpu in embedded system.
> 2. The file descriptors table is not shared among parent and child processes.
> Parent and children have its own fd table, because vfork() finally call
> clone() syscall without CLONE_FILES.
> 
> After vfork() and before exec(), just in the middle of vfork() and exec(),
> once the syslog() is launched and this 1st-time-call created the DGRAM socket
> to the /dev/log,

You aren't allowed to do very much between vfork() and exec().
Basically just sort out the child's fd table.
And I suspect that needs to only look at on-stack data.

Having the child execute first is only an optimisation.
The child can fault on paged-out memory (even its stack) which
would allow the parent to run.

        David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, 
UK
Registration No: 1397386 (Wales)

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to