File descriptors
What are File descriptors?
UNIX, the ancestor of Linux, championed a file-centric approach( If everything behaves like a file, you can use the same set of operations — read, write, close — on a wide range of resources, be it an actual file, a network socket, or even hardware devices), treating everything as a file for uniformity. File descriptors, basic non-negative integers, served as handles for diverse resources.
Example:
Let's illustrate this concept with an example. Suppose you want to read a file named "coolStuff.txt." The basic steps would involve:
Open the file: This action provides you with a file descriptor (let's say fd = 3).
Read or Write: Utilize the file descriptor (fd) to perform read or write operations on the data.
Close: Finally, close the file using the file descriptor (fd).
领英推荐
The Purpose: Why Do We Need File Descriptors?
File descriptors serve as this communication channel between the user-space applications and the kernel-space system calls for I/O operations. They create a neat, orderly way to deal with the chaos of data streams.
System calls:?
System call is a way of asking the kernel to do some work for us. For example, these are the four basic system calls that help to work with files in Linux
Delving into the world of file descriptors sparks curiosity about the intricate process through which programs use them to interact with files. This intriguing exploration merits further discussion in an upcoming post!
General Electric (GE) | Software Engineer
12 个月Yes, this is something! Knowledgeable