I think most of Python programmers are quite familar with using the builtin method open to open a file, which I mean a real file on disk, a stored file, like a txt file. But actually, we can also use the same open function to open a file descriptor. Normally, this is a better way to read and write files than by directly using os.read and os.write, which are both low level interfaces. I'll share my knowledge about open a file descriptor in this blog post. What is file descriptor? Technically speaking, a file descriptor is just a non-negative number which represents a I/O resource within a process, such as a disk file, a pipe, a socket or a device. We often use fd as a short hand name. Everything is a file in Linux! The most famous file descriptors for each process are 1, 2 and 3, which represent stdin, stdout and stderr respectively. They are created automatically for each process by operation system. We can check these file descriptors in...
Notes for Computer Science