Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site bsdpkh.UUCP Path: utzoo!linus!decvax!bellcore!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!akguc!codas!bsdpkh!latham From: latham@bsdpkh.UUCP (Ken Latham) Newsgroups: net.lang.c Subject: Re: Fork and Execl Message-ID: <172@bsdpkh.UUCP> Date: Fri, 21-Feb-86 17:12:08 EST Article-I.D.: bsdpkh.172 Posted: Fri Feb 21 17:12:08 1986 Date-Received: Mon, 24-Feb-86 08:28:24 EST References: <868@umd5.UUCP> Distribution: net Organization: AT&T-IS (SDSS), Orlando Fl. Lines: 39 > I've got a question ... >....but where does the execution of the child process continue from ? > In other words, if I wanted to put an execl() in the child to overwrite > the child, where would it go ? A common phrase used is: ......PARENT if ( (childid = fork()) == 0) { DO execl(); } if ( childid != -1 ) werror=wait(&status); /* status being a status structure */ REST OF PARENT ....; ( Yes, I know it's not standard indentation ..... :-) ) You get two complete copies of the process executing from the same point in process with the same data, stack ... well everything EXCEPT the return code from fork(). The parent gets the PID of the kid, the kid gets 0. ( other restrictions may apply see fork(2), void where prohibited) the execl() will never be executed if the fork() call fails. If you are using OS9 however you get a NEW process as a child ... never mind I'm getting carried away. Be careful the above will NOT work if the CHILD doesn't do an exec() of some kind ( or exit inside the if ). The child would execute what was inside the if ... drop out .... execute the parent code... etc. Although you may WANT to do this some times! Ken Latham, AT&T-IS (via AGS Inc.), Orlando , FL uucp: ihnp4!bsdpkh!latham