Fork and Execl

Ron Natalie <ron> ron at brl-smoke.ARPA
Sat Feb 22 04:49:55 AEST 1986


> After issuing the fork(), I know the parent process gets the pid of the
> child, and the child is a copy of the parent process, but where does the
> execution of the child process continue from ? (assuming the child process
> was created with no errors) In other words, if I wanted to put an execl()
> in the child to overwrite the child, where would it go ? Additionally, how
> can I be certain that I won't ever overwrite the parent process ?
> Without code fragments, I've not been able to get a clear picture of how
> this works.
> 
Neglecting certain funny versions of 4.2 as done by National Semiconductor,
the fork creates a totally seperate copy of all the nonshared program
sections.  This is entirely analogous to having allocated room for a new
running copy of the program.  Every program your shell starts up is handled
by fork and execl.  No working UNIX would overwrite the parent when the
child does something.

Since the NSC memory management unit is a little better than that of a VAX
they accomplish the same thing by setting all the writable areas to generate
a fault when accessed by either the parent or child.  It then makes a
seperate copy of just that page.

VFORK, in 4 BSD is a realization that many programs do fork/exec in quick
succession.  VFORK does not copy the data areas, but suspends the parent
until the child executes a separate exec.

-Ron



More information about the Comp.lang.c mailing list