Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: notesfiles Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!hplabs!hao!seismo!cmcl2!acf4!greenber From: greenber@acf4.UUCP Newsgroups: net.unix Subject: Re: Fork a shell Message-ID: <12700014@acf4.UUCP> Date: Fri, 7-Dec-84 19:31:00 EST Article-I.D.: acf4.12700014 Posted: Fri Dec 7 19:31:00 1984 Date-Received: Mon, 10-Dec-84 02:15:08 EST References: <-393000@uiucdcs.UUCP> Organization: New York University Lines: 42 Nf-ID: #R:uiucdcs:39300025:acf4:12700014:000:1914 Nf-From: acf4!greenber Dec 7 19:31:00 1984 <> C'mon....lets give this guy some info, folks.. In UNIX a process is really nothing but a collection of entries in a number of tables. The process table has one entry for each process. Each process also has additional entries in other tables. Some of these entries point to where the text (instructions) for the process reside, others point to the files that the process has open, etc. UNIX really is just manipulating table entries. When you fork a process, you are actually creating an exact (well almost!) duplicate of all the various tables and their entries. In fact, if you have a program that forks itself, there is only one way of telling which process is the parent and which is the child: the fork call returns the childs process id to the parent, and returns a zero to the child (unless there is an error condition, of course!) The next step in "forking a shell" is usually the 'exec' call. This call replaces the text (instruction) and data area for the process with something new and entirely different: a new program. This program COULD be a new shell, or anything else that you consider a program. Only certain parts of the old process (pre-exec, as it were) are preserved including, but not limited to, the environmental variables. The child inherits EVERYTHING from the parent, including open files, file pointers, etc. The interesting thing (to me, at least) about UNIX is that the only difference between a backround process and a foreground process is that the shell that was fork/exec'ed to the new piece of your bug-free program doesn't wait for the death of its child. Now some UNIX guru is about to come down from on high and tell us that I was wrong about something, or that I left out some vital piece of information. Well, let me get my umbrella before the downpour.. Hope this helps a little... Ross M. Greenberg @ NYU ----> allegra!cmcl2!acf4!greenber <----