Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Windows is actually much closer to this limited, meaningless, form of the "everything is a file" meme. In Windows literally every kernel object is a Handle. A file, a thread, a mutex, a socket - all Handles. In Linux, some of these are file descriptors, some are completely different things.

Of course, this is meaningless, as you can't actually do any common operation, except maybe Close*, on all of them. So them being the same type is actually a hindrance, not a help - it makes it easier to accidentally pass a socket to a function that expects a file, and will fail badly when trying to, for example, seek() in it.

* to be fair, Windows actually has WaitForSingleObject / WaitForMultipleObjects as well, which I think does do something meaningful for any Handle. I don't think Linux has anything similar.



> Of course, this is meaningless, as you can't actually do any common operation, except maybe Close*, on all of them.

You can write and read on anything on Unix that "is a file". You can't open or close all of them.

Annoyingly, files come in 2 flavors, and you are supposed to optimize your reads and writes differently.


You can call write() and read() on any file descriptor, but it won't necessarily do something meaningful. For example, calling them on a socket in listen mode won't do anything meaningful. And many special files don't implement at least one of read or write - for example, reading or writing to many of the special files in /proc/fs doesn't do anything.


You can try to read/write the same on Windows: ReadFile (and friends) take a HANDLE.

It won't make sense to try to read from all things you can get a HANDLE to on Windows either, but it's up to what created the HANDLE/object as to what operations are valid.

https://learn.microsoft.com/en-us/windows/win32/sysinfo/kern...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: