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 8319EBCAE for ; Thu, 30 Jun 2005 14:45:10 +0200 (CEST) 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 j5UCjA6g001107 for ; Thu, 30 Jun 2005 14:45:10 +0200 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 OAA17011 for ; Thu, 30 Jun 2005 14:45:09 +0200 (MET DST) Received: from first.in-berlin.de (dialin-145-254-052-199.arcor-ip.net [145.254.52.199]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j5UCj80F019827 for ; Thu, 30 Jun 2005 14:45:09 +0200 Received: by first.in-berlin.de (Postfix, from userid 501) id 2C82810E45A; Thu, 30 Jun 2005 14:44:50 +0200 (CEST) Date: Thu, 30 Jun 2005 14:44:50 +0200 From: Oliver Bandel To: caml-list@inria.fr Subject: Re: [Caml-list] Unix.waitpid Message-ID: <20050630124450.GD321@first.in-berlin.de> References: <26EB47FDD566A7469FC862DAF373792F07D4DC@kaiserslautern1.lmsintl.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <26EB47FDD566A7469FC862DAF373792F07D4DC@kaiserslautern1.lmsintl.com> User-Agent: Mutt/1.5.6i X-Miltered: at concorde with ID 42C3E956.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42C3E954.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; oliver:01 bandel:01 oliver:01 in-berlin:01 caml-list:01 waitpid:01 rec:01 waitpid:01 rec:01 reused:01 bandel:01 ...:98 wrote:01 unix:01 unix:01 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: On Thu, Jun 30, 2005 at 02:31:06PM +0200, Bauer, Christoph wrote: > Sorry, > > > let wait ?(delay_time = 0.01) pid idle x = > > let rec wait' () = > > idle x; > > delay delay_time; > > let pid = try fst (Unix.waitpid [Unix.WNOHANG] pid) with > > _ -> 1 in > > if pid <> 0 then wait' () > > in wait' () > this code is wrong, my original code was: > > let rec wait' () = > idle x; > delay delay_time; > let wpid = try fst( Unix.waitpid [Unix.WNOHANG] pid) with _ -> pid in > if pid <> wpid then wait' () > in wait' () Well, using the corresponding C-API-function, you should better rename your arguments: wpid is the pid you wait for (the argument to Unix.waitpid) and pid is the value you get from that function: ===== from the wait(2)/waitpid(2)-manpage ============= pid_t waitpid(pid_t wpid, int *status, int options); ======================================================= BTW: where do you set the "pid" initially? And: if waitpid returns with a pid, then you can't wait on this pid/process again. So, if you wait for one pid and get a different pid as result of the function call, then you wait again. But if you another time waits for a pid, which you alread caught (got as a result once before), then you can wait infinite, because that pid was caught by waitpud before... and you have to wait until the pid is reused by the kernel or wait until next reboot. ;-) So your concept seems to be buggy. Ciao, Oliver Bandel