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=1.2 required=5.0 tests=RCVD_IN_SORBS_WEB 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 96591BC69 for ; Fri, 14 Sep 2007 08:32:57 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAK7I6UbAXQImn2dsb2JhbACOEgEBAQEHBAYHCBg X-IronPort-AV: E=Sophos;i="4.20,253,1186351200"; d="scan'208";a="1180659" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 14 Sep 2007 08:33:28 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l8E6X8sx023315 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 14 Sep 2007 08:33:10 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAJnH6UbC2fJanmdsb2JhbACOFgEBAQEHBAYPGA X-IronPort-AV: E=Sophos;i="4.20,253,1186351200"; d="scan'208";a="2690063" Received: from anchor-post-32.mail.demon.net ([194.217.242.90]) by mail3-smtp-sop.national.inria.fr with ESMTP; 14 Sep 2007 08:33:26 +0200 Received: from orion.metastack.com ([80.177.38.218]) by anchor-post-32.mail.demon.net with esmtp (Exim 4.67) id 1IW4jz-000JLs-91 for caml-list@inria.fr; Fri, 14 Sep 2007 06:33:24 +0000 Received: from countertenor (are17.internetdsl.tpnet.pl [83.17.190.17]) (authenticated bits=0) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id l8E6Eij0013261 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Fri, 14 Sep 2007 07:14:45 +0100 From: "David Allsopp" To: "'Caml List'" References: Subject: RE: [Caml-list] Closing all open file descriptors Date: Fri, 14 Sep 2007 08:33:19 +0200 Organization: MetaStack Solutions Ltd. Message-ID: <006b01c7f699$275fd6d0$017ca8c0@countertenor> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 Thread-Index: Acf2W0hffQ+p+KWlR5Sbqxyx/vLNjwAPJ78g In-Reply-To: X-Miltered: at discorde with ID 46EA2B24.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; descriptors:01 descriptors:01 unix:01 unix:01 integer:01 caml-list:01 descriptor:02 descr:02 descr:02 irrelevant:07 probably:07 approach:08 wrap:08 i'm:09 daemon:10 > 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? Probably irrelevant here, but this approach wouldn't work under Windows (Unix.file_descr is the Win32 file handle at that point which is often larger than 1024). More relevantly, Unix can be reconfigured to allow for more than 1024 open files. Wouldn't an easier, portable way be to wrap Unix.openfile and Unix.close to maintain a set of open file_descrs or is your concern the risk of files left open by third party code? David