zhh zhh - 7 days ago 5
Linux Question

What if I don't call close(fd) function?

I use 'open' function to open a file, than I get a file descriptor 'fd', what if I don't call close(fd) before exiting my process?
Will the reference count of that file never become 0 and the space for that file never deallocate?

Answer

It will be closed by kernel properly. The reference count will be decreased and nothing will be leaked.