next up previous contents Back to Operating Systems Home Page
Next: Execution of programs inside Up: Block-oriented I/O in UNIX Previous: Reading & Writing

Closing files

It goes without saying that open files ought to be closed. This is automatically performed by the kernel when the a process exits, but since the number of available file descriptors is strictly limited, it's always a good practice to close files when they are not needed anymore.

File closing is performend by the close() system call, declared as

int close(int fildes);
The argument is the file descriptor of the file to be closed, and of course an error if reported if you pass a wrong (i.e. unopened) one.

Franco Callari