Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ut-sally.UUCP Path: utzoo!linus!philabs!seismo!ut-sally!jsq From: jsq@ut-sally.UUCP (John Quarterman) Newsgroups: net.unix-wizards Subject: Re: New? idea Message-ID: <783@ut-sally.UUCP> Date: Mon, 16-Jan-84 13:43:35 EST Article-I.D.: ut-sally.783 Posted: Mon Jan 16 13:43:35 1984 Date-Received: Tue, 17-Jan-84 02:38:49 EST References: <4771@umcp-cs.UUCP> Organization: U. Texas CS Dept., Austin, Texas Lines: 52 x From: chris@umcp-cs.UUCP Subject: New? idea Message-ID: <4771@umcp-cs.UUCP> Date: Sun, 15-Jan-84 17:43:17 CST Something that network servers often do is while ((netfd = netopen ()) >= 0) { if ((pid = fork ()) == 0) { if (fork ()) exit (0); workhorse (); exit (0); } close (netfd); } The purpose of the double-fork is to "disown" the actual worker and let the server continue to accept network connections. Without the "disownment", when the "workhorse" finishes and exit()s, it hangs around forever taking up a process slot, just so that it can return its status to its parent. But the server doesn't care, ergo the double-fork-be- inherited-by-init trick. So, my suggestion is a "disown" system call, to allow parents to give up their children so that on exit they will vanish without a trace. Does anyone know why this should not be implemented (other than because you can do it without this)? Alternatively, does anyone have better ideas? That's called a spawn. For it to work correctly, you need to have a wait: while ((netfd = netopen ()) >= 0) { if ((pid = fork ()) == 0) { if (fork ()) exit (0); workhorse (); exit (0); } wait (0); /* clean up child, leave granchild */ close (netfd); } and some error checking and fork retrying is quite useful in practice. I prefer SIGCHLD, myself. It's too bad select wasn't made general enough to allow selecting on dead or stopped processes as well as file and socket conditions. -- John Quarterman, CS Dept., University of Texas, Austin, Texas {ihnp4,seismo,ctvax}!ut-sally!jsq, jsq@ut-sally.{ARPA,UUCP}