Sunday, September 22, 2024

Re: Need some information about fork(2) -- Pedantic Correction

>
> It's an exact copy, all memory allocations remain the same.
>

Please forgive the pedantic correction, but, although I don't know how
OpenBSD does it, I certainly hope that OpenBSD does it the way other
operating systems do it: the memory in the child process is not "an
exact copy" -- the memory is not copied at all, but it is marked "copy
on write" so that a copy of a page will be made when either the parent
or the child alters it. But as long as neither parent nor child
alters the memory there is no need to make a copy of it. Certainly if
the fork() will be followed soon afterward by an exec(), copying all
that memory which is all going to be freed up a microsecond later
anyway would be folly.

Similarly, a later poster made a comparison to a file copy: there are
now two copies of a file, altering one does not alter the other. Now
again, I don't know how the native OpenBSD filesystem does it, but I
hope that (at least as a mount or tunefs option, you might not want it
in every case) the native OpenBSD filesystem does it the way ZFS and
other proper filesystems do it: the data blocks are not copied, but
they are marked "copy on write" and a copy is made when either file is
altered. As long as neither file is altered, there is no need to copy
the data blocks on which the file resides.

And yes, I do know that OpenBSD refuses to support ZFS, because
OpenBSD is terrified of the patent, or maybe it's a copyright, even
though FreeBSD and NetBSD have no fear of it. But I digress.


Jay F. Shachter
6424 North Whipple Street
Chicago IL 60645-4111
+1 773 7613784 landline
+1 410 9964737 GoogleVoice
http://m5.chicago.il.us
jay@m5.chicago.il.us

"But when she traced the killer's IP address ... it was in the 192.168/16 block!"

No comments:

Post a Comment