From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA32716; Wed, 17 Jul 2002 16:07:25 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA32644 for ; Wed, 17 Jul 2002 16:07:24 +0200 (MET DST) Received: from cirse.saclay.cea.fr (cirse.saclay.cea.fr [132.166.192.127]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6HE7NX23113 for ; Wed, 17 Jul 2002 16:07:23 +0200 (MET DST) Received: from argiope.saclay.cea.fr (argiope.saclay.cea.fr [132.166.192.108]) by cirse.saclay.cea.fr (8.12.2/8.12.2/CEAnet-Internet.1.0) with ESMTP id g6HE7NcH012706 for ; Wed, 17 Jul 2002 16:07:23 +0200 (MEST) Received: from muguet.saclay.cea.fr (unverified) by argiope.saclay.cea.fr (Content Technologies SMTPRS 4.2.10) with ESMTP id for ; Wed, 17 Jul 2002 16:00:08 +0200 Received: from is002254.saclay.cea.fr (is002254.saclay.cea.fr [132.166.134.67]) by muguet.saclay.cea.fr (8.12.2/8.12.2/CEAnet-Interne.1.0) with ESMTP id g6HE7MlU005718; Wed, 17 Jul 2002 16:07:22 +0200 (MEST) Received: from basile by is002254.saclay.cea.fr with local (Exim 3.35 #1 (Debian)) id 17UpRp-0004sP-00; Wed, 17 Jul 2002 16:06:33 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <15669.31207.415691.386109@is002254.saclay.cea.fr> Date: Wed, 17 Jul 2002 16:06:31 +0200 To: caml-list@inria.fr Subject: [Caml-list] Unix subdaemon, channels, filedescriptors.... X-Mailer: VM 7.03 under Emacs 21.2.1 From: Basile STARYNKEVITCH Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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