Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 _ -> ()
   done;

Is there a better way?

Thanks,
Dave