Ameba Ownd

アプリで簡単、無料ホームページ作成

bleedinspookcoun1981's Ownd

Unix philosophy everything is a file

2022.01.14 16:27


->>>> Click Here to Download <<<<<<<-





















Windows' concept of the filesystem is a hodgepodge; it makes distinctions between directories, drives, and network resources. There are three different syntaxes, all blended together in Windows: the Unix-like.. It is why there are so many illegal characters in Windows file names.


Unix has a unified filesystem, with everything accessed by a single common scheme. Local files, external media, and network shares all get treated the same way.


Windows can achieve similar ends to my disk image example above, but you have to use special programs written by uncommonly talented programmers.


This is why there are so many "virtual DVD" type programs on Windows. The lack of a core OS feature has created an artificial market for programs to fill the gap, which means you have a bunch of people competing to create the best virtual DVD type program.


The same goes for other tools like disk wiping programs, which we also don't need on Unix systems. Want your CF card's contents irretrievably scrambled instead of just zeroed? On Linux, we don't keep reinventing such wheels because the core OS features not only work well enough, they work so well they're used pervasively. For just one example, a typical scheme for booting a Linux box involves a virtual disk image created using techniques like I show above.


This is not to say that Windows doesn't have a command line, or that it lacks many command line programs. Windows even has a very powerful command shell these days, appropriately called PowerShell. Yet, there are knock-on effects of this lack of a command-line tradition. That allows your script to do error handling on a step-by-step basis. What does all this have to do with "everything is a file"? Pipes are unidirectional streams , not random-access like a regular disk file, but in many cases the difference is of no consequence.


The important thing is that you can attach two independently developed programs and make them communicate via simple text. In that sense, any two programs designed with the Unix Way in mind can communicate. But why write the output to a temporary file when the "everything is a file" philosophy gives you a better way? If all you want to do is read the output of that command into a vi editor buffer, vi can do that for you directly. From the vi "normal" mode, say:.


That inserts that program's output into the active editor buffer at the current cursor position. Under the hood, vi is using pipes to connect the output of the program to a bit of code that uses the same OS calls it would use to read from a file instead. I wouldn't be surprised if the two cases of :r — that is, with and without the! I can't think of a good reason not to. This isn't a recent feature of vi , either; it goes clear back to the ancient ed 1 text editor.


For a second example of this, recall my mutt email command above. If I didn't care about the file's name, I could have used process substitution to avoid creating the temporary file:. For yet a third way this powerful idea appears in Unix, consider gdb on Linux systems. Programmers coming to Unix from other systems look at gdb and almost invariably gripe about it, "Yuck, it's so primitive! There aren't competing low-level debuggers on most Unix systems because there is no need for programs to compete at that level.


All we need is one good low-level tool that we can all base our high-level tools on, if that low-level tool communicates easily via pipes. This means we now have a documented debugger interface which would allow drop-in replacement of gdb. It's unfortunate that the primary competitor to gdb didn't take this low-friction path , but that quibble aside, lldb is just as scriptable as gdb.


To pull the same thing off on a Windows box, the creators of the replaceable tool would have had to define some kind of formal plugin or automation API. That means it doesn't happen except for the very most popular programs, because it's a lot of work to build both a normal command line user interface and a complete programming API.


This magic happens through the grace of pervasive text-based IPC. Although Windows' kernel has Unix-style anonymous pipes , it's rare to see normal user programs use them for IPC outside of a command shell, because Windows lacks this tradition of creating all core services in a command line version first, then building the GUI on top of it separately.


This leads to being unable to do some things without the GUI, which is one reason why there are so many remote desktop systems for Windows, as compared to Linux.


This is doubtless part of the reason why Linux is the operating system of the cloud, where everything's done by remote management. Command line interfaces are easier to automate than GUIs in large part because "everything is a file. Consider SSH. You may ask, how does it work? Now your remote system is connected to your local one through a connection that so seamlessly matches the Unix Way that you can pipe data through the SSH connection , if you need to.


A piped text stream is indistinguishable from a file from a program's perspective, except that it's unidirectional. A program reads from a pipe the same way it reads from a file: through a file descriptor. If you need to automate such a program, you must also write a COM or.


NET program. This is a fair bit more difficult than setting up a pipe on a Unix box. The practical difference between the Windows registry and the Unix Way of system configuration also illustrates the benefits of the "everything is a file" philosophy. On Unix type systems, I can look at system configuration information from the command line merely by examining files. I can change system behavior by modifying those same files.


For the most part, these configuration files are just plain text files, which means I can use any tool on Unix to manipulate them that can work with plain text files. Scripting the registry is not nearly so easy on Windows. That isn't really "scripting," since it doesn't let you do anything conditionally: it's all or nothing.


If your registry changes need any amount of logic, the next easiest option is to learn PowerShell , which amounts to learning. NET system programming. It would be like if Unix only had Perl, and you had to do all ad hoc system administration through it. Now, I'm a Perl fan, but not everyone is. Unix lets you use any tool you happen to like, as long as it can manipulate plain text files.


Since it is a Bash feature, rather a kernel feature, it isn't visible outside of Bash or on systems that don't use Bash at all. This shows, by counterexample, why it is such a good idea to make all data resources visible through the filesystem. Although Windows tries to prevent you from creating a NUL file, it is possible to bypass this protection with mere trickery , fooling Windows' file name parsing logic.


Millions of people visit TecMint! If you like what you are reading, please consider buying us a coffee or 2 as a token of appreciation. We are thankful for your never ending support. Hi, I am just understanding all these stuff. What is the relation between socket files and ports e. Ports are communication end-points that are associated with different applications on an operating system such as 80 for HTTP server, 22 for SSH etc. Applications listen on a particular port and clients that want to request services or connect to them do that via the port.


On the other hand, a socket file allows communication between processes over a network after a connection between two applications via a port. In conclusion, a client must first access an application running on a network via a port, before two or more processes on the client and application can communicate via a socket: a socket is bound to a port number.


Once the communication is stablished through the port btw, these ports are physically associated only to the CPU? How these tasks avoid to get lost in the network or motherboard? A kind of header mentioning the port in each socket files just created, for example? As i mentioned before, all sockets in an application are bound to the port used by the application.


Considering a connection-oriented over a network client-to-server model, when the server is running, the socket on it waits for requests from a client for a service s. The server first of all establishes binds an address that clients can use to find the server process; then it waits for clients to requests. Great explanation of the different types of files and some useful examples of how they can be used.


Thank you! Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.


Save my name, email, and website in this browser for the next time I comment. But PowerShell largely supports the same kind of compositional design, just with streams of objects instead of streams of text.


It inter-operates acceptably with text streams by having some implicit conversions one of which is almost always used, to display results to the console. It tries to shoot for a somewhat more complicated design by necessity it has to work with Windows APIs as they already exist, after all , but it manages to deliver the extra features that make that complexity tolerable.


PowerShell can actually work with tree-like data, albeit through the lens of objects. Since everything is an object instead, you end up liberated from having just the one, single file interface.


Instead, you can work with objects that implement almost any interface. More complexity, but more powerful, too, and sometimes that can be a worthwhile trade. Composition is a hugely useful tool in designing a system like this. Re-use is a secondary goal. We can start with type of the basic piece: perhaps a process, with an environment, command line arguments, stdin, stdout, stderr, and a return code.


Then we can start figuring out all the ways we might want to compose such a thing. Usually, though not always, we want to be able to create a bigger value of that type out of smaller values of that type. Sometimes, we want to glue together pieces of different types. And so on. Once we have figured out all the different ways things can be put together, we just need to start trying to use such a system.


Almost any composition is going to look like a tree or at least a DAG, and maybe sometimes a graph, though more rarely. This is one of the most basic structures we need to be able to represent.


But for the category theory-averse: no worries, none today. Write programs to work together. Write programs to handle text streams, because that is a universal interface. Other formulations start to get into more direct guidance also from the above Wikipedia link : Make each program do one thing well.