You are not logged in.

#1 2018-05-29 14:10:39

jumper149
Member
Registered: 2018-02-07
Posts: 6

Are all files on the harddrive?

I think im correct if i say "everything is a file" is a part of the UNIX philosophy, but what about files that are constantly written to or are read.
For example files like 'proc/stat' or the files where your thermal information is stored and so on...

Is linux writing them again every few ticks or are they just changed in RAM.
Also: What if Im accessing those files?

Ty for help smile

Last edited by jumper149 (2018-05-29 14:11:14)

Offline

#2 2018-05-29 14:21:41

Haller
Member
Registered: 2018-04-08
Posts: 35

Re: Are all files on the harddrive?

/proc is part of the RAM. It's not written to your hard drive.

You can read these files. That's why they are there.
Changing i.e. /proc/uptime with an editor will fail / isn't possible.

Offline

#3 2018-05-29 14:29:35

ayekat
Member
Registered: 2011-01-17
Posts: 1,259
Website

Re: Are all files on the harddrive?

"Everything is a file" really just means: "You can interact with every aspect of the system with just regular file operations (open, read, write, ...)".

You typically interact with data on disks through so called filesystems. Filesystems are a system component that present you the data in some accessible form (rather than having to read the raw bytes manually from offsets on the disk); and they may do many sophisticated things, like showing files that do not really exist, or that exist elsewhere (network filesystems like nfs or cifs/samba/sshfs).

The proc filesystem really just takes the current kernel state, and presents its data as files (like /proc/stat). Whenever you read such a file (say, with `cat`), the proc filesystem does some magic stuff behind the scenes that I will not explain in more detail because my own knowledge is a bit fuzzy (e.g. fetches information from the kernel), and then returns the data as if you had just read it from any regular file.

EDIT: Other examples are the device files in /dev/input/, which allow you to read e.g. periphery device information (like mouse movement).

EDIT2: Ah yes, ewaller below has a link that explains this a bit better.

Last edited by ayekat (2018-05-29 14:34:34)

Offline

#4 2018-05-29 14:30:01

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 16,117

Re: Are all files on the harddrive?

Haller wrote:

/proc is part of the RAM. It's not written to your hard drive.

Not really. Yes, there are RAM based file systems (tmpfs), but stuff in /proc and /sys are pseudo files whose content is dynamically created by the kernel when you read the "file".  This provides a mechanism whereby a user space program can obtain certain information about the kernel state. Also, for those pseudo files, when you write to those which permit it, the kernel reads the stream and can use the data in it to change its internal state.

https://en.wikipedia.org/wiki/Synthetic_file_system

Edit: Snaked by Ayekat

Edit 2:  To directly answer the OP, no those data are not written to disk.  For more information, study the output of mount.  Look at the file system types of /sys and /proc

Last edited by ewaller (2018-05-29 14:34:37)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2018-05-29 14:34:35

Haller
Member
Registered: 2018-04-08
Posts: 35

Re: Are all files on the harddrive?

@ewaller: Thanks for correction.

Offline

#6 2018-05-29 14:54:04

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 19,952
Website

Re: Are all files on the harddrive?

Yes, "everything" is a file (though really plan 9 has a broader definition of "everything").  But, as is clarified well above, a file need not be on a disk.  "File" in this sense basically means it has a path/name.  You can generally interact with them using file interactions, but this in fact is actually quite limited.  Many of the interesting "files" do not allow seek operations and may not be writable.  So to me, the relevant part of being a "file" is just having a path/name.

I see an analogy to web servers.  With Apache, urls map to actual on disk files.  With nginx, cherrypy, and various other modern servers, a url may never map to a file.  Instead some program interprets the url and determines what to return.  But the client interacting with the server need not know or care about this.  When you `curl http://domain.tld/path/to/file` and get a response, from your perspective "/path/to/file" is a file on the domain.tld server ... whether it actually is or not.

So different web servers may or may not map urls to actual files, but from the clients perspective everything has a file-like-path.  In unix, the kernel, or udev/mdev, or any number of other processes may respond to requests for /path/to/file and return data as if it was a file, whether or not it really is behind the scenes.

So pedantically, perhaps we should say "Everything acts like a file" rather than "Everything is a file".


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB