* [Caml-list] Child process doesn't terminate
@ 2014-03-24 18:23 Johan Grande
2014-03-24 21:28 ` Gerd Stolpmann
2014-03-24 22:55 ` oliver
0 siblings, 2 replies; 5+ messages in thread
From: Johan Grande @ 2014-03-24 18:23 UTC (permalink / raw)
To: caml users
Hi,
In the following program, the child process "cat" never terminates. I
don't understand why; can anyone tell me?
~~~
let _ =
let open Unix in
let indescr, outdescr = pipe () in
let outchan = out_channel_of_descr outdescr in
let pid =
create_process "/bin/cat" [|"cat"|]
indescr stdout stderr
in
Printf.fprintf outchan "Hello!\n%!";
close indescr;
close outdescr;
ignore (waitpid [] pid) (* stuck here *)
~~~
--
Johan Grande
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Child process doesn't terminate
2014-03-24 18:23 [Caml-list] Child process doesn't terminate Johan Grande
@ 2014-03-24 21:28 ` Gerd Stolpmann
2014-03-24 23:59 ` Johan Grande
2014-03-24 22:55 ` oliver
1 sibling, 1 reply; 5+ messages in thread
From: Gerd Stolpmann @ 2014-03-24 21:28 UTC (permalink / raw)
To: Johan Grande; +Cc: caml users
[-- Attachment #1: Type: text/plain, Size: 1054 bytes --]
Am Montag, den 24.03.2014, 19:23 +0100 schrieb Johan Grande:
> Hi,
>
> In the following program, the child process "cat" never terminates. I
> don't understand why; can anyone tell me?
Because outdescr isn't closed in the child. Set the close-on-exec flag
on it.
Gerd
> ~~~
> let _ =
> let open Unix in
> let indescr, outdescr = pipe () in
> let outchan = out_channel_of_descr outdescr in
> let pid =
> create_process "/bin/cat" [|"cat"|]
> indescr stdout stderr
> in
> Printf.fprintf outchan "Hello!\n%!";
> close indescr;
> close outdescr;
> ignore (waitpid [] pid) (* stuck here *)
> ~~~
>
> --
> Johan Grande
>
--
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de
My OCaml site: http://www.camlcity.org
Contact details: http://www.camlcity.org/contact.html
Company homepage: http://www.gerd-stolpmann.de
------------------------------------------------------------
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Child process doesn't terminate
2014-03-24 21:28 ` Gerd Stolpmann
@ 2014-03-24 23:59 ` Johan Grande
0 siblings, 0 replies; 5+ messages in thread
From: Johan Grande @ 2014-03-24 23:59 UTC (permalink / raw)
To: Gerd Stolpmann; +Cc: caml users
Le 24/03/2014 22:28, Gerd Stolpmann a écrit :
> Am Montag, den 24.03.2014, 19:23 +0100 schrieb Johan Grande:
>> In the following program, the child process "cat" never terminates. I
>> don't understand why; can anyone tell me?
>
> Because outdescr isn't closed in the child. Set the close-on-exec flag
> on it.
Indeed, set_close_on_exec did the trick. Thanks!
--
Johan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Child process doesn't terminate
2014-03-24 18:23 [Caml-list] Child process doesn't terminate Johan Grande
2014-03-24 21:28 ` Gerd Stolpmann
@ 2014-03-24 22:55 ` oliver
2014-03-25 0:10 ` Johan Grande
1 sibling, 1 reply; 5+ messages in thread
From: oliver @ 2014-03-24 22:55 UTC (permalink / raw)
To: Johan Grande; +Cc: caml users
Hello,
On Mon, Mar 24, 2014 at 07:23:05PM +0100, Johan Grande wrote:
> Hi,
>
> In the following program, the child process "cat" never terminates.
> I don't understand why; can anyone tell me?
>
> ~~~
> let _ =
> let open Unix in
> let indescr, outdescr = pipe () in
> let outchan = out_channel_of_descr outdescr in
> let pid =
> create_process "/bin/cat" [|"cat"|]
> indescr stdout stderr
> in
> Printf.fprintf outchan "Hello!\n%!";
> close indescr;
> close outdescr;
> ignore (waitpid [] pid) (* stuck here *)
> ~~~
"cat" does not terminate.
With
create_process "/bin/cat" [| "cat"; "/etc/passwd" |]
cat would terminate after cat'ing the file,
otherwise it reads from input until Ctrl-D arrives,
before printing the data and then terminates.
So you can wait in vain with your waitpid-call,
if you call it as you did.
Ciao,
Oliver
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Child process doesn't terminate
2014-03-24 22:55 ` oliver
@ 2014-03-25 0:10 ` Johan Grande
0 siblings, 0 replies; 5+ messages in thread
From: Johan Grande @ 2014-03-25 0:10 UTC (permalink / raw)
To: oliver; +Cc: caml users
Le 24/03/2014 23:55, oliver a écrit :
> On Mon, Mar 24, 2014 at 07:23:05PM +0100, Johan Grande wrote:
>> In the following program, the child process "cat" never terminates.
>> I don't understand why; can anyone tell me?
>>
>> [...]
>
> With
>
> create_process "/bin/cat" [| "cat"; "/etc/passwd" |]
>
> cat would terminate after cat'ing the file,
> otherwise it reads from input until Ctrl-D arrives,
> before printing the data and then terminates.
Yes, but if I'm not mistaken I can't just send Ctrl+D to the process.
The equivalent here is to close the channel; Gerd pointed out how to do
this properly.
--
Johan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-03-25 0:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-24 18:23 [Caml-list] Child process doesn't terminate Johan Grande
2014-03-24 21:28 ` Gerd Stolpmann
2014-03-24 23:59 ` Johan Grande
2014-03-24 22:55 ` oliver
2014-03-25 0:10 ` Johan Grande
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox