Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Operating Systems
Operating Systemsmedium

What are file descriptors and how does I/O buffering work?

Tags
#file-descriptors#io#buffering
Back to categoryPractice quiz

Answer

A file descriptor is a numeric handle to an open file or socket. Buffering batches I/O in memory to reduce syscalls and improve throughput, at the cost of delayed writes.

Advanced answer

Deep dive

Descriptors are OS-managed references:

  • Each process has a descriptor table.
  • Descriptors refer to kernel objects (files, sockets, pipes).
  • Buffering reduces syscall overhead and enables readahead.
  • fsync/flush forces data to disk when durability matters.

Examples

Buffered write flow:

write() -> user buffer -> kernel buffer -> disk later
fsync() -> force disk commit

Common pitfalls

  • Forgetting to close descriptors (leaks).
  • Assuming buffered writes are durable.
  • Mixing buffered and unbuffered I/O incorrectly.

Interview follow-ups

  • What happens on a partial write?
  • How do pipes use file descriptors?
  • When do you need fsync or O_DIRECT?

Related questions

Operating Systems
What is memory-mapped I/O (mmap) and when would you use it?
#mmap#memory#io
Java
What is try-with-resources and why should you use it?
#try-with-resources#autocloseable#io