Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!mit-eddie!ll-xn!ames!oliveb!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: Fork and Join, Pipe in C Message-ID: <22256@sun.uucp> Date: Sun, 28-Jun-87 01:48:46 EDT Article-I.D.: sun.22256 Posted: Sun Jun 28 01:48:46 1987 Date-Received: Sun, 28-Jun-87 09:40:31 EDT References: <7737@brl-adm.ARPA>, <1186@ius2.cs.cmu.edu> <8174@utzoo.UUCP> <113@xyzzy.UUCP> Sender: news@sun.uucp Lines: 38 > But fork() can *never* be as efficent as vfork(), and sometimes this > efficency is crucial. Yes, there is a savings if you can avoid copying the VM data structures, but this savings will be less than the savings from not copying the pages themselves. I'm not convinced that this savings will necessarily be enough to justify "vfork". (TOPS-20, and I presume TENEX, had the equivalent of "fork" and "exec", and used copy-on-write, but didn't provide the equivalent of "vfork". I don't know if they just didn't bother or if they determined that it wouldn't be worth it. It may be that on systems other than 10s and 20s, or OSes other than TOPS-20/TENEX, the overhead of copying the VM data structures would be greater, due to larger address spaces, smaller page sizes, more complicated data structures, etc..) > If you think the operation is not interesting and common, note how many > zillions of library routines use fork() or vfork() immediately followed > by exec(), and provoke the kernel into doing all sorts of unnecessary > work, even if that kernel implements copy-on-demand. Sometimes "fork" or "vfork" is *not* immediately followed by "exec". If the program to be run in the new process is not to inherit its set of open files from its parent, the child process has to rearrange the file descriptors before doing an "exec". The "create_process" call would have to include options for closing descriptors, opening files, and moving descriptors around. (This is the approach taken in VMS; the SYS$CREPRC call includes options for redirecting various I/O channels.) It might also have to include options for manipulating signals. A lot of systems don't provide separate "fork" and "exec" calls, but do provide a call like "create_process". (BTW, "rename" had nothing to do with NFS; it appeared in 4.2BSD.) Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com