From: Basile STARYNKEVITCH <basile.starynkevitch@cea.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Unix subdaemon, channels, filedescriptors....
Date: Wed, 17 Jul 2002 16:06:31 +0200 [thread overview]
Message-ID: <15669.31207.415691.386109@is002254.saclay.cea.fr> (raw)
Dear All,
Sorry to coming back on channels and unix filedescriptors....
My problem:
I am coding in Ocaml a daemon program (the Poesia monitor - see
http://www.poesia-filter.org/) which happens to launch daemon
subprocesses, i.e. it fork and execs processes which do not use their
stdin stdout and stderr. Basically I would need something like a
Unix.process_none which forks a command without any stdin stdout and
stderr (which are technically redirected to /dev/null).
In practice I expect my poesia monitor to have lots (=hundreds) of
opened file descriptors, and I would like the child process to have no
file descriptor opened except stdin stdout stderr
I would like to close all the filedescriptors after the
fork. Unfortunately, the caml_out_channels_list primitive (coded in C
in ocaml/byterun/io.c), which is used in stdlib/pervasives.ml is not
published in pervasives.mli, and there is no caml_in_channels_list
primitive
May I suggest publishing this primitive in the future ocaml v3.05?
Also, Unix.open_process_in and related seems to forget closing the
file descriptors in the child process, as this example (running only
on Linux) demonstrates:
#load "unix.cma";;
(* opening bogus stuff *)
let fooch = open_out "/tmp/foo" and barch = open_out "/tmp/bar" ;;
(* demonstrating that the opened process has fooch and barch still opened *)
let lsch = Unix.open_process_in "ls -l /proc/self/fd" in
let rec loop () =
try
Printf.printf "%s\n" (input_line lsch); flush stdout;
loop ()
with End_of_file -> ()
in
loop ();
Unix.close_process_in lsch
When running this stuff, I am getting
total 0
lr-x------ 1 basile basile 64 Jul 17 15:57 0 -> pipe:[4700690]
l-wx------ 1 basile basile 64 Jul 17 15:57 1 -> pipe:[4700695]
l-wx------ 1 basile basile 64 Jul 17 15:57 2 -> pipe:[4700689]
l-wx------ 1 basile basile 64 Jul 17 15:57 3 -> /tmp/foo
l-wx------ 1 basile basile 64 Jul 17 15:57 4 -> /tmp/bar
lr-x------ 1 basile basile 64 Jul 17 15:57 5 -> /proc/18709/fd
I think that the child process (running the command) should not have
other opened filedescriptors than the documented stdin, stdout,
stderr, or that this behavior should be documented
How do I close (in Ocaml) every channel except stdin, stdout, stderr?
Regards.
--
N.B. Any opinions expressed here are only mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.
---------------------------------------------------------------------
Basile STARYNKEVITCH ---- Commissariat à l Energie Atomique * France
DRT/LIST/DTSI/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX
phone:+33 1,6908.6055; fax: 1,6908.8395 home: 1,4665.4553; mobile: 6,8501.2359
work email: Basile point Starynkevitch at cea point fr
home email: Basile at Starynkevitch point net
-------------------
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
next reply other threads:[~2002-07-17 14:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-17 14:06 Basile STARYNKEVITCH [this message]
2002-07-17 16:05 ` Bruno.Verlyck
2002-07-19 13:08 ` Xavier Leroy
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=15669.31207.415691.386109@is002254.saclay.cea.fr \
--to=basile.starynkevitch@cea.fr \
--cc=caml-list@inria.fr \
/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