Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!brl-smoke!ron From: ron@brl-smoke.ARPA (Ron Natalie ) Newsgroups: net.lang.c Subject: Re: Fork and Execl Message-ID: <1212@brl-smoke.ARPA> Date: Fri, 21-Feb-86 13:49:55 EST Article-I.D.: brl-smok.1212 Posted: Fri Feb 21 13:49:55 1986 Date-Received: Mon, 24-Feb-86 08:11:14 EST References: <868@umd5.UUCP> Distribution: net Organization: Ballistic Research Lab (BRL) Lines: 26 > 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