Java Zero to All All questionsPractise free
Interview questions › Linux, Networking & Observability › Linux Essentials & Shell

What is a file descriptor, and how does the 'too many open files' error happen and get fixed?

Level III · MidLinux Essentials & Shell
Short answer

A file descriptor is a small integer the kernel hands out for every open file, socket, and pipe a process holds, and each process has a soft and hard limit (ulimit -n).

Explanation

A Java service that leaks connections or never closes streams (missing try-with-resources, an unbounded HTTP connection pool) keeps accumulating descriptors until open() fails with 'Too many open files,' which surfaces as failed DB connections or dropped sockets. Diagnose with lsof -p <pid> or ls /proc/<pid>/fd | wc -l, raise the limit in limits.conf or the systemd unit's LimitNOFILE, but treat a steadily climbing count as a leak to fix, not just a ceiling to raise.

Common mistakes
  • Raising ulimit without finding the leak.
  • Not checking for unclosed streams or sockets.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Linux Essentials & Shell.

Practise free

More on Linux Essentials & Shell