From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 9E00ABBCA for ; Mon, 14 Apr 2008 15:31:08 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: At0AAK/5AkjU4363mWdsb2JhbACBXo92AQEBAQEIBQcJFpgJAQ X-IronPort-AV: E=Sophos;i="4.25,655,1199660400"; d="scan'208";a="11429721" Received: from moutng.kundenserver.de ([212.227.126.183]) by mail3-smtp-sop.national.inria.fr with ESMTP; 14 Apr 2008 15:31:08 +0200 Received: from gate.lan.gerd-stolpmann.de (dslb-084-059-097-242.pools.arcor-ip.net [84.59.97.242]) by mrelayeu.kundenserver.de (node=mrelayeu3) with ESMTP (Nemesis) id 0MKxQS-1JlOm22xCD-0003FV; Mon, 14 Apr 2008 15:31:06 +0200 Received: from [192.168.0.32] (fw.lan.gerd-stolpmann.de [192.168.1.1]) by gate.lan.gerd-stolpmann.de (Postfix) with ESMTP id 6766DC141; Mon, 14 Apr 2008 15:31:06 +0200 (CEST) Subject: Re: [Caml-list] Unix.create_process vs Unix.open_process_out From: Gerd Stolpmann To: James Jones Cc: caml-list@yquem.inria.fr In-Reply-To: <20080414125557.11200@gmx.com> References: <20080414125557.11200@gmx.com> Content-Type: text/plain Date: Mon, 14 Apr 2008 15:32:08 +0200 Message-Id: <1208179928.18538.8.camel@flake.lan.gerd-stolpmann.de> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX1/n6tfe3lkUCT41ghLexiJw4EyW+qo7F13wLvk LHAJ7xKeTgsqHGW+EL7WZVE2ZmpRXlKri2h51NBxFIZKaMQsIe y/A+l9n1hACBB/G7a4DctbMpX+r76x8 X-Spam: no; 0.00; gerd:01 stolpmann:01 stdout:01 stderr:01 waitpid:01 stdin:01 descriptors:01 descriptors:01 gerd:01 beginner's:01 ocaml:01 bug:01 stolpmann:01 viktoriastr:01 64293:01 Am Montag, den 14.04.2008, 08:43 -0400 schrieb James Jones: > Consider the following two functions: > > let test1 () = > let w = Unix.open_process_out "cat" in > assert (Unix.close_process_out w = Unix.WEXITED 0) > > let test2 () = > let r,w = Unix.pipe () in > let pid = Unix.create_process "cat" [| "cat" |] r Unix.stdout > Unix.stderr in > Unix.close w; > assert (snd (Unix.waitpid [] pid) = Unix.WEXITED 0) > > > Both execute "cat" and then close its stdin immediately. Ahem, the second version doesn't. Note that there are 4 involved descriptors: r and w before forking, and r and w after forking (resp., the descriptors in the calling and in the called program). You close only one of the w's, so the pipe remains open. > This should cause cat to terminate. In test1 this works as expected > but in test2, cat keeps running forever. Is this the expected behavior > of Unix.create_process? Yes. Gerd > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs -- ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------