Live data from Hacker News

In Unix Everything Is a File

ph7spot.com

31–40 of 57 posts

Re: In Unix Everything Is a File

#31
post #20
post #3

Wordpress strikes again. Page is from 2014. Archive link: https://web.archive.org/web/20091119184152/https://ph7spot.c... Edit: archive of 6 years ago with some styling: http://archive.is/B9He (The page actually loaded for me on the second try, and the design looks a lot more modern now.)

Your link says the page is from 2009, not 2014 (2009-11-19 to be exact).

Oh right, my bad. I just saw a first archive.org index at 2014 but that is of course not necessarily the time of writing/publication.

Re: In Unix Everything Is a File

#32
post #19

And if you use XML, all you need to do, is to add another forward slash after the filename. And now, the network, the host and the data have become one: Everything is a node (or an atomic value). But hey, that's stupid. Let's not do that...!

By way of XPath. I don't disagree but--that's stupid because of... using XML at all? Complications of altering/documenting ad hoc taxonomies? Mixing paradigms under a unified syntax? Something else?

Re: In Unix Everything Is a File

#33
post #6

Is the sendfile system call still the fastest way to transfer data locally on Linux systems? For communicating between processes running locally on system. Or, for example, a server running locally on an android device. Unix domain sockets typically beat TCP connections for most large file transfers. But is there anything faster? And what about transfers over the public net from machine to machine? I usually just use…

That depends on what you're doing. Sendfile, splice and copy_file_range are the fastest if you want to shovel things back and forth between file descriptors. The latter supports reflink copy if the the underlying filesystem does.

And I think there's some special casing in vmsplice that lets you transfer memory pages from process to process over a pipe. At least I've seen some patches for that, not sure if they made it into the kernel. Alternatively there's memfd.

But if you want to coordinate processes you'll use a shared memory and futexes.

If you just want to hand over an entire file to a different process you can send the file descriptor itself over a unix socket.

Re: In Unix Everything Is a File

#34
post #4

Which was the last Unix release/flavor where you could still read(2) a directory? All manpages that I've found say that you get EISDIR if you try it.

FreeBSD would allow this as of a few years ago (2007 at the earliest).

Still does. I'm running 12-CURRENT and it looks like UFS allows it. I occasionally cat or more a directory by accident and get a screen full of junk.

Re: In Unix Everything Is a File

#35
post #30

I like the Linus Torvalds' interpretation: that (almost) everything is actually a file descriptor. The few things that are not, like fork() returns, are subject to criticism (DJB wrote about how fork() should return an fd, I just couldn't find the URL right now.)

This? http://cr.yp.to/docs/selfpipe.html

> Richard Stevens's 1992 book ``Advanced programming in the UNIX environment'' says that you can't safely mix select() or poll() with SIGCHLD (or other signals). The SIGCHLD might go off while select() is starting, too early to interrupt it, too late to change its timeout.

Solution: the self-pipe trick. Maintain a pipe and select for readability on the pipe input. Inside the SIGCHLD handler, write a byte (non-blocking, just in case) to the pipe output. Done.

Of course, the Right Thing would be to have fork() return a file descriptor, not a process ID.

Re: In Unix Everything Is a File

#36
post #30

I like the Linus Torvalds' interpretation: that (almost) everything is actually a file descriptor. The few things that are not, like fork() returns, are subject to criticism (DJB wrote about how fork() should return an fd, I just couldn't find the URL right now.)

This? http://cr.yp.to/docs/selfpipe.html > Richard Stevens's 1992 book ``Advanced programming in the UNIX environment'' says that you can't safely mix select() or poll() with SIGCHLD (or other signals). The SIGCHLD might go off while select() is starting, too early to interrupt it, too late to change its timeout. Solution: the self-pipe trick. Maintain a pipe and select for readability on the pipe input. Inside the S…

I have a faint recall of a DJB text with more in-depth discussion around the topic, thanks anyway for providing a true reference!

Re: In Unix Everything Is a File

#37
post #36

Earlier quoted context omitted.

This? http://cr.yp.to/docs/selfpipe.html > Richard Stevens's 1992 book ``Advanced programming in the UNIX environment'' says that you can't safely mix select() or poll() with SIGCHLD (or other signals). The SIGCHLD might go off while select() is starting, too early to interrupt it, too late to change its timeout. Solution: the self-pipe trick. Maintain a pipe and select for readability on the pipe input. Inside the S…

I have a faint recall of a DJB text with more in-depth discussion around the topic, thanks anyway for providing a true reference!

You're welcome! I found the link here: http://www.greenend.org.uk/rjk/tech/fork.html

Re: In Unix Everything Is a File

#38
post #10

Any UNIX old timer knows that actually: In UNIX everything is a file, except when it is not.

> In Plan 9 , everything is a file Fixed that.

NT's everything is an object is a much more rational design. OS X is based off similar concepts except in the kernel thanks to NextStep.

Re: In Unix Everything Is a File

#39
post #26

Earlier quoted context omitted.

> In Plan 9 , everything is a file Fixed that.

> > In Plan 9, everything is a file > Fixed that. It was a short snarky comment. Also the article mentions that too at the bottom. Yeah they "fixed it" but by that time not enough people cared. The abstraction purity was nice and developers and OS fans loved it, but it just didn't matter for most application. Another way to put it is that Linux was already fairly decent and it wasn't worth switching to a whole new OS…

I understand why it didn't take off, but I don't think it's true that Plan 9 was just a tiny incremental improvement over UNIX's architecture. Modern networking and distributed systems would be a LOT nicer today if Plan 9 had taken off in the 90s. I think the economic benefit over today's state of affairs would have been massive, not just something that appealed to computer geeks' sense of elegance.

Re: In Unix Everything Is a File

#40
post #33
post #6

Is the sendfile system call still the fastest way to transfer data locally on Linux systems? For communicating between processes running locally on system. Or, for example, a server running locally on an android device. Unix domain sockets typically beat TCP connections for most large file transfers. But is there anything faster? And what about transfers over the public net from machine to machine? I usually just use…

That depends on what you're doing. Sendfile, splice and copy_file_range are the fastest if you want to shovel things back and forth between file descriptors. The latter supports reflink copy if the the underlying filesystem does. And I think there's some special casing in vmsplice that lets you transfer memory pages from process to process over a pipe. At least I've seen some patches for that, not sure if they made i…

>>> you can send the file descriptor itself over a unix socket

Oh, that is genius ;)

Described in detail here, from Stevens Unix Network Programming

http://www.masterraghu.com/subjects/np/introduction/unix_net...

Post reply on HN