File descriptors represent open resources such as files and sockets. They need lifecycle ownership even when memory is managed automatically.
Before you start
You should understand processes, threads, memory and basic file operations. Track ownership and state changes over time. For concurrent scenarios, write down at least two possible execution orders; the same instructions can behave differently when scheduling or resource availability changes.
The practical goal is to reason through this situation: A server leaking sockets eventually cannot open more connections. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Identify resource handles
Files and sockets consume bounded operating-system resources.
Step 2: Assign explicit closure
Memory reclamation is not timely lifecycle management.
Step 3: Trace failure paths
Leaks often occur only after errors or cancellation.
Worked scenario
A server leaking sockets eventually cannot open more connections.
A server opens a socket for each upstream attempt but closes it only on success. Repeated failures eventually exhaust descriptors, preventing new connections despite available heap memory. Raising the descriptor limit postpones the symptom; reliable cleanup addresses the ownership defect.
Common mistake
Garbage collection is not a reliable timely descriptor-release policy.
Verify the behavior
Count descriptors through repeated success, failure and cancellation cycles.
Interview exercise
Investigate descriptor exhaustion.
Answer and reasoning
Count open resource types, trace creation and closure paths and verify cleanup under errors and cancellation.
Continue learning
Compare the scenario with the Operating Systems interview questions and test your understanding with the Operating Systems MCQs. For terminology and implementation details, consult the reference material.