close()¶
Purpose¶
close() releases a file descriptor.
After close(), the file descriptor number may be reused by the kernel for another open file.
Header¶
Prototype¶
Parameters¶
| Parameter | Description |
|---|---|
fd |
File descriptor to release. |
Return Value¶
Returns 0 on success. Returns -1 on failure and sets errno.
Minimal Example¶
Common Pitfalls¶
- Using an fd after it has been closed.
- Closing the same fd twice.
- Forgetting to remove a closed fd from
epollbookkeeping. - Not resetting local fd variables to
-1after cleanup.