3

In C++, is there a way to check if a file descriptor is still open, long after it was initially opened?

poy
  • 10,063
  • 9
  • 49
  • 74

2 Answers2

3

You can use fcntl with the F_GETFL to get if the fd is valid or not.

Community
  • 1
  • 1
Milan
  • 15,389
  • 20
  • 57
  • 65
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