In C++, is there a way to check if a file descriptor is still open, long after it was initially opened?
            Asked
            
        
        
            Active
            
        
            Viewed 1,986 times
        
    2 Answers
3
            You can use fcntl with the F_GETFL to get if the fd is valid or not.
- 
                    If the file descriptor was closed, fcntl will fail. (So it doesn't matter whether you use F_GETFL or any other command.) – William Pursell May 12 '11 at 14:25
 
2
            
            
        fstat is the most portable way I can think of.
If you tell us what platform, we may be able to suggest something better for your particular situation.
        Ben Voigt
        
- 277,958
 - 43
 - 419
 - 720