[quote='789258022, on-d-go, /thread/756183?answerId=789258022#789258022, /profile/on-d-go']
I would expect fileDescriptor1 to read from file1
[/quote]
As I wrote in my original reply, Why would you expect that?
The behaviour of file descriptors is well-defined. The behaviour you are seeing is allowed by the spec.
What’s actually happening is that the kernel is allocating the same FD for the second open as for the first, which it can do because you closed the first one. So when you read, you read from the second file.
What are you actually trying to achieve here? There may be other APIs that better match your requirements. If you really want to use file descriptors you need to understand them properly. You will be constantly surprised if you try to guess how you would expect them to behave.
Topic:
App & System Services
SubTopic:
Core OS
Tags: