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.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 0CB7DBC69 for ; Fri, 14 Sep 2007 01:24:17 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAL9j6UbAXQInmWdsb2JhbACOFwEBAQEHBAYHCBY X-IronPort-AV: E=Sophos;i="4.20,251,1186351200"; d="scan'208";a="16175364" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 Sep 2007 01:24:44 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l8DNOTU9013873 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 14 Sep 2007 01:24:29 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CADNj6UZA9hw0/2dsb2JhbAA X-IronPort-AV: E=Sophos;i="4.20,251,1186351200"; d="scan'208";a="2683663" Received: from tenhost.net ([64.246.28.52]) by mail3-smtp-sop.national.inria.fr with SMTP; 14 Sep 2007 01:24:42 +0200 Received: (qmail 25216 invoked by uid 502); 13 Sep 2007 17:56:14 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 13 Sep 2007 17:56:14 -0500 Date: Thu, 13 Sep 2007 17:56:14 -0500 (CDT) From: Dave Benjamin X-X-Sender: ramen@tenhost.net To: Caml List Subject: Closing all open file descriptors Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 46E9C6AD.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 benjamin:01 descriptor:02 descr:02 i'm:09 dave:09 dave:09 daemon:10 magic:10 file:11 file:11 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? Thanks, Dave