* [Caml-list] Unix.wait: strange behavior
@ 2002-09-08 10:29 Yang Shouxun
2002-09-08 11:30 ` Remi VANICAT
2002-09-14 3:19 ` Yang Shouxun
0 siblings, 2 replies; 3+ messages in thread
From: Yang Shouxun @ 2002-09-08 10:29 UTC (permalink / raw)
To: caml-list
Hi,
I'm reading ocaml-book English version. On p. 611:
----8<----
match Unix.fork () with
0 -> Printf.printf "fair Marquise " ; flush stdout
| _ -> ignore (Unix.wait ()) ;
match Unix.fork () with
0 -> Printf.printf "your beautiful eyes " ; flush stdout
| _ -> ignore (Unix.wait ()) ;
match Unix.fork () with
0 -> Printf.printf "make me die " ; flush stdout
| _ -> ignore (Unix.wait ()) ;
Printf.printf "of love\n" ;
flush stdout
----8<----
this is intended to show the use of Unix.wait to wait for the
termination of the child.
Strangely, when I input at the Ocaml toplevel, it does not print "fair
Marquise your beautiful eyes make me die of love", but only "fair
Marquise". The forked processes did not terminate for some reason, which
I don't understand why. Is this a bug?
Guessing that the child processes will not automatically exit, I added
"; exit 0" to the lines for newly forked processes, and I got "your
beautiful eyes make me die of love" printed before the return of the
expression and then "fair Marquise " printed.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Unix.wait: strange behavior
2002-09-08 10:29 [Caml-list] Unix.wait: strange behavior Yang Shouxun
@ 2002-09-08 11:30 ` Remi VANICAT
2002-09-14 3:19 ` Yang Shouxun
1 sibling, 0 replies; 3+ messages in thread
From: Remi VANICAT @ 2002-09-08 11:30 UTC (permalink / raw)
To: caml-list
Yang Shouxun <yangsx@fltrp.com> writes:
> Hi,
>
> I'm reading ocaml-book English version. On p. 611:
> ----8<----
> match Unix.fork () with
> 0 -> Printf.printf "fair Marquise " ; flush stdout
> | _ -> ignore (Unix.wait ()) ;
> match Unix.fork () with
> 0 -> Printf.printf "your beautiful eyes " ; flush stdout
> | _ -> ignore (Unix.wait ()) ;
> match Unix.fork () with
> 0 -> Printf.printf "make me die " ; flush stdout
> | _ -> ignore (Unix.wait ()) ;
> Printf.printf "of love\n" ;
> flush stdout
> ----8<----
> this is intended to show the use of Unix.wait to wait for the
> termination of the child.
>
> Strangely, when I input at the Ocaml toplevel, it does not print "fair
> Marquise your beautiful eyes make me die of love", but only "fair
> Marquise". The forked processes did not terminate for some reason,
> which I don't understand why. Is this a bug?
Mmm, Don't know if this a bug or not, but the problem is that after
forking, you have two toplevel, so personally I've something like :
# match Unix.fork () with
0 -> Printf.printf "fair Marquise " ; flush stdout
[....]
fair Marquise - : unit = ()
# #quit
;;
your beautiful eyes - : unit = ()
# #quit ;;
make me die - : unit = ()
# #quit ;;
of love
- : unit = ()
#
>
> Guessing that the child processes will not automatically exit, I added
> "; exit 0" to the lines for newly forked processes, and I got "your
> beautiful eyes make me die of love" printed before the return of the
> expression and then "fair Marquise " printed.
Strange, I've the waited output.
--
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Unix.wait: strange behavior
2002-09-08 10:29 [Caml-list] Unix.wait: strange behavior Yang Shouxun
2002-09-08 11:30 ` Remi VANICAT
@ 2002-09-14 3:19 ` Yang Shouxun
1 sibling, 0 replies; 3+ messages in thread
From: Yang Shouxun @ 2002-09-14 3:19 UTC (permalink / raw)
To: caml-list
As a follow-up to my initial post, I found that the strange behavior is
due to the difference of toplevel and byte-compiled. The code, when
byte-compiled, will act as described in the book. When run at the
interactive toplevel, acts as I reported.
That's a good lesson for me that there are big differences between the
three different modes.
Yang Shouxun wrote:
> Hi,
>
> I'm reading ocaml-book English version. On p. 611:
> ----8<----
> match Unix.fork () with
> 0 -> Printf.printf "fair Marquise " ; flush stdout
> | _ -> ignore (Unix.wait ()) ;
> match Unix.fork () with
> 0 -> Printf.printf "your beautiful eyes " ; flush stdout
> | _ -> ignore (Unix.wait ()) ;
> match Unix.fork () with
> 0 -> Printf.printf "make me die " ; flush stdout
> | _ -> ignore (Unix.wait ()) ;
> Printf.printf "of love\n" ;
> flush stdout
> ----8<----
> this is intended to show the use of Unix.wait to wait for the
> termination of the child.
>
> Strangely, when I input at the Ocaml toplevel, it does not print "fair
> Marquise your beautiful eyes make me die of love", but only "fair
> Marquise". The forked processes did not terminate for some reason, which
> I don't understand why. Is this a bug?
>
> Guessing that the child processes will not automatically exit, I added
> "; exit 0" to the lines for newly forked processes, and I got "your
> beautiful eyes make me die of love" printed before the return of the
> expression and then "fair Marquise " printed.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-09-14 3:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-08 10:29 [Caml-list] Unix.wait: strange behavior Yang Shouxun
2002-09-08 11:30 ` Remi VANICAT
2002-09-14 3:19 ` Yang Shouxun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox