From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 99A0BBC69 for ; Fri, 14 Sep 2007 12:09:47 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANf66UbAXQInmWdsb2JhbACOEQEBAgcEBgcIFg X-IronPort-AV: E=Sophos;i="4.20,255,1186351200"; d="scan'208";a="1190985" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 14 Sep 2007 12:10:19 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l8EAA0Ha002308 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 14 Sep 2007 12:10:02 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAF766UbU4363nmdsb2JhbACOEQEBAgcEBg8Y X-IronPort-AV: E=Sophos;i="4.20,255,1186351200"; d="scan'208";a="763242" Received: from moutng.kundenserver.de ([212.227.126.183]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Sep 2007 12:10:16 +0200 Received: from dslb-084-059-098-078.pools.arcor-ip.net [84.59.98.78] (helo=gate.lan.gerd-stolpmann.de) by mrelayeu.kundenserver.de (node=mrelayeu4) with ESMTP (Nemesis), id 0ML21M-1IW87n0RYN-0006Nu; Fri, 14 Sep 2007 12:10:13 +0200 Received: from flakew.lan.gerd-stolpmann.de (fw.lan.gerd-stolpmann.de [192.168.1.1]) by gate.lan.gerd-stolpmann.de (Postfix) with ESMTP id BDDE9C0C6; Fri, 14 Sep 2007 12:10:10 +0200 (CEST) Subject: Re: [Caml-list] Closing all open file descriptors From: Gerd Stolpmann To: Dave Benjamin Cc: Caml List In-Reply-To: References: Content-Type: text/plain Date: Fri, 14 Sep 2007 12:10:09 +0200 Message-Id: <1189764610.22131.13.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX18F1cZkRXFI0to46kE7nw1soJpJJaR3Te2RfjF gydLYvAUwbtX3W1Kq7DkFHJwManOjYAv3utjsovuPgpFLYBpk4 LV/u/upkGY4RlZM3Q1Hf3rlbDG5VY+m X-Miltered: at concorde with ID 46EA5DF8.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; descriptors:01 gerd:01 stolpmann:01 donnerstag:01 descriptors:01 gerd:01 stolpmann:01 viktoriastr:01 64293:01 darmstadt:01 6151:01 6151:01 unix:01 unix:01 integer:01 Am Donnerstag, den 13.09.2007, 17:56 -0500 schrieb Dave Benjamin: > I'm writing a daemon and I would like to be able to close all open file > descriptors. As far as I can tell, there is no way to determine the > maximum number of file descriptors available, and neither is there a way > to get a file descriptor from an integer. The best I've come up with is > the following: > > for fd = 0 to 1024 do > try Unix.close (Obj.magic fd : Unix.file_descr) > with Unix.Unix_error _ -> () > done; > > Is there a better way? Not really. Unix wants it this way. ocamlnet's netsys library has functions to deal with that: Netsys.file_descr_of_int and Netsys.sysconf_open_max. Look here for the code: https://godirepo.camlcity.org/wwwsvn/trunk/code/src/netsys/?root=lib-ocamlnet2 This does not work under Win32, of course, but I bet this wasn't part of your question. The Netsys functions fail in this case. Gerd -- ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------