3

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

poy
  • 9,640
  • 9
  • 43
  • 71

2 Answers2

3

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

Community
  • 1
  • 1
Milan
  • 14,611
  • 20
  • 53
  • 64
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
  • 269,602
  • 39
  • 394
  • 697