English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Closing all open file descriptors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-09-13 (23:24)
From: Dave Benjamin <dave@r...>
Subject: Closing all open file descriptors
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 _ -> ()

Is there a better way?