caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Keith Wansbrough <Keith.Wansbrough@cl.cam.ac.uk>
To: micha-1@fantasymail.de
Cc: "caml-list" <caml-list@inria.fr>
Subject: Re: [Caml-list] fork question...
Date: Fri, 25 Feb 2005 11:02:27 +0000	[thread overview]
Message-ID: <E1D4dEp-0002zH-00@mta1.cl.cam.ac.uk> (raw)
In-Reply-To: Your message of "Fri, 25 Feb 2005 11:20:18 +0100." <200502251120.18831.micha-1@fantasymail.de>

> hi,
> 
> below is a code piece of the ocaml-book. What I don't understand is why is 
> there the second fork() ? Maybe that's a Unix question, but I saw it the 
> first time in the ocaml book :-)

It's a Unix question, not an OCaml one.  The reason is to completely
dissolve the connection between the parent process and the grandchild.
Normally, the parent is responsible for cleaning up after the child -
in particular, wait()ing on it to obtain its return status.  In
situations like this, where establish_server doesn't want to wait for
server_fun to complete, you do the following:

* fork()
* in parent, wait for child to exit
* in child, fork() again
* in grandchild, do your work
* in child, exit.  This means the grandchild is orphaned, and "init"
  (PID 1) adopts it and takes responsibility for cleaning up after it.
* in parent, clean up after child
* in parent, continue

If you don't do this, your process table fills up with zombie
processes (processes that have completed, but haven't yet been
wait()ed for.

See any standard Unix text (eg Stevens, Unix Network Programming).

HTH.

--KW 8-)


  reply	other threads:[~2005-02-25 11:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-25 10:20 Micha
2005-02-25 11:02 ` Keith Wansbrough [this message]
2005-02-25 13:26   ` [Caml-list] " Christophe TROESTLER

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1D4dEp-0002zH-00@mta1.cl.cam.ac.uk \
    --to=keith.wansbrough@cl.cam.ac.uk \
    --cc=caml-list@inria.fr \
    --cc=micha-1@fantasymail.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).