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.0 required=5.0 tests=HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id D7497BBCA for ; Mon, 14 Apr 2008 14:56:00 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj8EAHrxAkhK0AVDZGdsb2JhbACCQzMpiA+GGRoCDAWYBA X-IronPort-AV: E=Sophos;i="4.25,655,1199660400"; d="scan'208,217";a="9554675" Received: from mail.gmx.com ([74.208.5.67]) by mail2-smtp-roc.national.inria.fr with SMTP; 14 Apr 2008 14:56:00 +0200 Received: (qmail 13108 invoked by uid 0); 14 Apr 2008 12:55:57 -0000 Received: from 67.177.185.135 by www-us014.gmx.net with HTTP; Mon, 14 Apr 2008 08:55:57 -0400 (EDT) Content-Type: multipart/alternative; boundary="========GMXBoundary11201208177757800755" Date: Mon, 14 Apr 2008 08:43:14 -0400 From: "James Jones" Message-ID: <20080414125557.11200@gmx.com> MIME-Version: 1.0 subject: Unix.create_process vs Unix.open_process_out To: caml-list@yquem.inria.fr X-Authenticated: #46952340 X-Flags: 0001 X-Mailer: WWW-Mail 6107 (Global Mail Exchange) X-Priority: 3 X-Provags-ID: V01U2FsdGVkX1+8TNsgoBm8tDKSLLO/fOk9h/TSYDTCt9DFAnMTvK Ce7VwvsY2amvTwYE7drDe2isWh8A1GV1jIGQ== X-Registered: 0 X-GMX-UID: FRJlIghyzmCiIe496icly6hiamdhZMR7 X-Spam: no; 0.00; stdout:01 stderr:01 waitpid:01 stdin:01 stdout:01 stderr:01 waitpid:01 stdin:01 height:98 border-left:98 ccc:98 padding-left:98 unix:01 unix:01 font-size:98 X-Attachments: cset="utf-8" --========GMXBoundary11201208177757800755 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit 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. 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? --========GMXBoundary11201208177757800755 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Consider the following two functions:

let test1 () =3D
  let= w =3D Unix.open_process_out "cat" in
  assert (Unix.close_process_= out w =3D Unix.WEXITED 0)

let test2 () =3D
  let r,w =3D Uni= x.pipe () in
  let pid =3D Unix.create_process "cat" [| "cat" |] r = Unix.stdout Unix.stderr in
  Unix.close w;
  assert (snd (U= nix.waitpid [] pid) =3D Unix.WEXITED 0)


Both execute "cat" and t= hen close its stdin immediately. This should cause cat to terminate. In tes= t1 this works as expected but in test2, cat keeps running forever. Is this = the expected behavior of Unix.create_process? --========GMXBoundary11201208177757800755-- 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.0 required=5.0 tests=none 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 25143BBCA for ; Mon, 14 Apr 2008 15:20:55 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtQAABv3AkiS6EANmmdsb2JhbACRVQEBAQEBCAUJBxaYBA X-IronPort-AV: E=Sophos;i="4.25,655,1199660400"; d="scan'208";a="11429228" Received: from unknown (HELO mail3.sun.ac.za) ([146.232.64.13]) by mail3-smtp-sop.national.inria.fr with ESMTP; 14 Apr 2008 15:20:53 +0200 Received: from werkesel.sun.ac.za ([146.232.129.30]) by mail3.sun.ac.za with esmtp (Exim 4.63) (envelope-from ) id 1JlOc2-0003LP-16 for caml-list@yquem.inria.fr; Mon, 14 Apr 2008 15:20:46 +0200 Received: from js by werkesel.sun.ac.za with local (Exim 4.69) (envelope-from ) id 1JlOc1-0006sv-Hm for caml-list@yquem.inria.fr; Mon, 14 Apr 2008 15:20:45 +0200 Date: Mon, 14 Apr 2008 15:20:45 +0200 From: Johann Spies To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Unix.create_process vs Unix.open_process_out Message-ID: <20080414132045.GA26399@sun.ac.za> Mail-Followup-To: Johann Spies , caml-list@yquem.inria.fr References: <20080414125557.11200@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080414125557.11200@gmx.com> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Spam: no; 0.00; spies:01 jspies:01 stdout:01 stderr:01 waitpid:01 stdin:01 stdin:01 spies:01 universiteit:01 stellenbosch:01 021:98 asunder:98 wrote:01 unix:01 unix:01 On Mon, Apr 14, 2008 at 08:43:14AM -0400, James Jones wrote: > 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. 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? Did you try "cat " ? If you just type 'cat' on the commandline it waits for input on stdin. If you 'cat ' it finishes the job and exit. Regards Johann -- Johann Spies Telefoon: 021-808 4036 Informasietegnologie, Universiteit van Stellenbosch "For the word of God is quick, and powerful, and sharper than any twoedged sword, piercing even to the dividing asunder of soul and spirit, and of the joints and marrow, and is a discerner of the thoughts and intents of the heart." Hebrews 4:12 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 ------------------------------------------------------------ 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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 72729BBCA for ; Mon, 14 Apr 2008 15:35:17 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvwAAJ76AkjU4368k2dsb2JhbACBXo92AQEBAQkDCQkWmAgB X-IronPort-AV: E=Sophos;i="4.25,655,1199660400"; d="scan'208";a="24975188" Received: from moutng.kundenserver.de ([212.227.126.188]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 Apr 2008 15:35:17 +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-1JlOq33nIH-0003V8; Mon, 14 Apr 2008 15:35:16 +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 A2E87C141; Mon, 14 Apr 2008 15:35:15 +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:36:18 +0200 Message-Id: <1208180178.18538.10.camel@flake.lan.gerd-stolpmann.de> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX19CDdvawF031QpzqBd6yu27qHOw4g1TtD/VppT LnF5p/vI0q7NypM35PcN8UeUAWmbSrl89iBLPJdUODl6Qjprpq JlFID0JoB3gnreGjrbyKJi14oe2QLMl X-Spam: no; 0.00; gerd:01 stolpmann:01 stdout:01 stderr:01 waitpid:01 stdout:01 stderr:01 waitpid:01 gerd:01 stdin:01 beginner's:01 ocaml:01 bug:01 stolpmann:01 viktoriastr: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) P.S. You can close the "other" w by setting the close on exec flag: let test2 () = let r,w = Unix.pipe() in Unix.set_close_on_exec w; let pid = Unix.create_process "cat" [| "cat" |] r Unix.stdout Unix.stderr in Unix.close w; assert (snd (Unix.waitpid [] pid) = Unix.WEXITED 0);; Gerd > > > Both execute "cat" and then close its stdin immediately. 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? > _______________________________________________ > 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 ------------------------------------------------------------