Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!veritas!amdcad!dgcad!dg-rtp!hunt From: hunt@dg-rtp.rtp.dg.com (Greg Hunt) Newsgroups: comp.unix.questions Subject: Re: vfork() Keywords: vfork() Message-ID: <1991Mar19.181626.28739@dg-rtp.dg.com> Date: 19 Mar 91 18:16:26 GMT References: <8372@rsiatl.Dixie.Com> Sender: hunt@hobbit.rtp.dg.com (Greg Hunt) Reply-To: hunt@dg-rtp.rtp.dg.com Distribution: usa Organization: Data General Corp., Research Triangle Park, NC Lines: 50 In article <8372@rsiatl.Dixie.Com>, stan@Dixie.Com (Stan Brown) writes: > > A quick question. I have run into a couple of packages that > use a routine called vfork(). My libraries/system cals don't > include this. > > Could someone tell me how this is different from fork() > Also any ideas on how to implemet it using fork() (or > otherwise) would be appreicated. The vfork(2) system call does the same thing as the fork(2) system call except that the child process shares the same address space as the parent process, instead of having a complete copy of the parent's address space made for it during the fork. It uses the same mechanism as fork(2) to indicate which process is the child (the call returns zero) and which process is the parent (the call returns the PID of the child). This is a more efficient way of forking processes that are simply going to immediately do an exec(2) of some sort to load and execute a different executable. Avoiding the copying of the parent's address space can save a fair bit of time. Using vfork(2), however, has some gotchas. Since the child is sharing the parent's address space, the child must be extremely careful about modifiying anything in the address space, since those changes will affect the parent process when it regains control after the child has executed an exec(2) of some sort, exit'ed, or terminated abnormally. This means it can't return from the routine that it's in, and it must be extremely careful about changing global and local variables, etc. You should be able to replace the vfork(2) calls with fork(2) calls, but you need to see what, if any, changes the child is making to the parent's address space before it does its exec(2) call. If the child isn't changing anything, then replacing the vfork(2) calls with fork(2) calls should work without problems. If however, the child is changing parts of the parent's address space, then you'll have to figure out some other way for the child to communicate those changes to the parent, since with the fork(2) the child won't be sharing the address space with the parent. Maybe you can figure out a way to make the changes in other local variables before the fork(2), and then have the parent copy those new local variables into the real local or global variables that the child wanted to alter. Hope this helps. Good luck! -- Greg Hunt Internet: hunt@dg-rtp.rtp.dg.com DG/UX Kernel Development UUCP: {world}!mcnc!rti!dg-rtp!hunt Data General Corporation Research Triangle Park, NC, USA These opinions are mine, not DG's.