From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 460D4BC75 for ; Fri, 25 Feb 2005 12:04:29 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1PB4SQK005507 for ; Fri, 25 Feb 2005 12:04:28 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA05191 for ; Fri, 25 Feb 2005 12:04:28 +0100 (MET) Received: from mta1.cl.cam.ac.uk (mta1.cl.cam.ac.uk [128.232.0.15]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j1PB2S5q005930 for ; Fri, 25 Feb 2005 12:04:28 +0100 Received: from zonule.cl.cam.ac.uk ([128.232.9.23] helo=cl.cam.ac.uk ident=[/EOj4uERDdcXLzXS7Nhh5oPHEnq0B+0b]) by mta1.cl.cam.ac.uk with esmtp (Exim 3.092 #1) id 1D4dEp-0002zH-00; Fri, 25 Feb 2005 11:02:27 +0000 X-Mailer: exmh version 2.6.3-CL 04/04/2003 with nmh-1.0.4 X-Exmh-Isig-CompType: repl X-Exmh-Isig-Folder: cslists/caml To: micha-1@fantasymail.de Cc: "caml-list" Subject: Re: [Caml-list] fork question... In-reply-to: Your message of "Fri, 25 Feb 2005 11:20:18 +0100." <200502251120.18831.micha-1@fantasymail.de> Mime-Version: 1.0 Content-Type: text/plain Date: Fri, 25 Feb 2005 11:02:27 +0000 From: Keith Wansbrough Message-Id: X-Miltered: at nez-perce with ID 421F063C.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 ocaml:01 orphaned:01 ...:98 unix:01 unix:01 programming:03 fork:04 fork:04 exit:04 exit:04 table:93 standard:07 maybe:07 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: > hi, > > below is a code piece of the ocaml-book. What I don't understand is why is > there the second fork() ? Maybe that's a Unix question, but I saw it the > first time in the ocaml book :-) It's a Unix question, not an OCaml one. The reason is to completely dissolve the connection between the parent process and the grandchild. Normally, the parent is responsible for cleaning up after the child - in particular, wait()ing on it to obtain its return status. In situations like this, where establish_server doesn't want to wait for server_fun to complete, you do the following: * fork() * in parent, wait for child to exit * in child, fork() again * in grandchild, do your work * in child, exit. This means the grandchild is orphaned, and "init" (PID 1) adopts it and takes responsibility for cleaning up after it. * in parent, clean up after child * in parent, continue If you don't do this, your process table fills up with zombie processes (processes that have completed, but haven't yet been wait()ed for. See any standard Unix text (eg Stevens, Unix Network Programming). HTH. --KW 8-)