From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 33E23BC75 for ; Fri, 25 Feb 2005 11:22:03 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j1PAK356027210 for ; Fri, 25 Feb 2005 11:22:03 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA03822 for ; Fri, 25 Feb 2005 11:20:01 +0100 (MET) Received: from mxintern.schlund.de (mxintern.kundenserver.de [212.227.126.204]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1PAK0lt031921 for ; Fri, 25 Feb 2005 11:20:01 +0100 Received: from [172.17.36.11] (helo=schluck.use.schlund.de) by mxintern.kundenserver.de with esmtp (TLSv1:RC4-MD5:128) (Exim 4.34) id 1D4cZk-0005rE-H0 for caml-list@inria.fr; Fri, 25 Feb 2005 11:20:00 +0100 From: Micha Reply-To: micha-1@fantasymail.de To: "caml-list" Subject: fork question... Date: Fri, 25 Feb 2005 11:20:18 +0100 User-Agent: KMail/1.7.91 X-Techauftrag: 007 MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200502251120.18831.micha-1@fantasymail.de> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Virus-Scanned: Symantec AntiVirus Scan Engine X-Miltered: at nez-perce with ID 421EFBD0.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 sockaddr:01 sockaddr:01 outchan:01 outchan:01 waitpid:01 ...:98 unix:01 unix:01 match:02 descr:02 descr:02 let:03 let:03 fork:04 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO 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 :-) Michael let establish_server server_fun sockaddr = let domain = domain_of sockaddr in let sock = Unix.socket domain Unix.SOCK_STREAM 0 in Unix.bind sock sockaddr ; Unix.listen sock 3; while true do let (s, caller) = Unix.accept sock in match Unix.fork() with 0 -> if Unix.fork() <> 0 then exit 0 ; (* <<<< ???? *) let inchan = Unix.in_channel_of_descr s and outchan = Unix.out_channel_of_descr s in server_fun inchan outchan ; close_in inchan ; close_out outchan ; exit 0 | id -> Unix.close s; ignore(Unix.waitpid [] id) done ;;