What is a file descriptor?
9 April 2023 (Updated 9 April 2023)
In a nutshell
In Unix-like operating systems, a file descriptor is an integer that uniquely identifies an open file or stream (e.g., socket). It’s generated when a file is created or opened and is used by the calling process to refer to the file in subsequent calls.
Reserved file descriptors
| File descriptor | Description |
| 0 | stdin |
| 1 | stdout |
| 2 | stderr |
View file descriptors used by a process
Run
lsof -p <process-id>
If your process uses stdin, stdout, or stderr, you should see an entry with 0, 1, or 2 as the FD (file descriptor) value.
Tagged:
Unix
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment