/proc is quite useful when it comes to hiding root on Android.
I didn’t know any of this. Amazing. I usually just look at
/proc/net/for routes and bonding config etc.I’m surprised it doesn’t mention that
/proc/selfautomagically points to the directory of the current process. So if you’re writing a program, you can just look there for information about itselfI love *nix’s commitment to the bit on the core abstractions.

Okay, this is legitimately cool as heck. This finally helps me wrap my head around the “everything is a file” concept in Linux. Of course it can just copy the executable to memory for later reference. That’s how the system would not completely have a meltdown when you do live updates.
Excellent share!
I bet this is done with inodes. Deleted files aren’t truely deleted until nothing has it open and its inode gets dropped. Like ARC for files.
You can also do interesting things like overwrite a “file” (as in a specific filesystem path) with new contents while keeping anything that already has the file open on the old contents by unlinking the old inode to the path and writing the new contents under a new inode. I believe mv does this. The kind of lesser known feature that probably strikes a good balance between preventing super annoying silent errors/corruption and causing them.
It’s a bit more interesting than that…
Linux, unlike Windows, will let you delete a file that is actively in use. It removes the reference on the file system but the contents of the file won’t be deleted until all file pointers to it close. In fact it will still be seen as taking up disk space until it’s garbage collected (deleting a large file that’s in use can be frustrating).
So the file is actually still available to that running process. If you replace it with a new executable and run that then you get the new version.
I’m aware of /proc but usually use lsof to find open fd’s for a process.
Is one better than the other?
lsofjust reads from/procand gives you formatted outputhttps://github.com/lsof-org/lsof/blob/master/lib/dialects/linux/dproc.c#L297
Julia Evans has such great and accessible content, they’re awesome
they are a youtuber?
Better, they make zines! https://jvns.ca/
thanks, it’s got really hard nowdays to find quality content.
I am saving this, both for the post AND for the comments.
We need the whole set of these in one post
THERE’S MORE?
Did you know openBSD does not have this folder? I think the BSD’s do not use /proc. I do not know why though.
Damn, I really could have made a lot of use of this over the last 20+ years… Thanks for sharing!
This is awesome, and I really no no idea about this!
I no no idea you liked this, nice
d’oh! That’s what I get for trying to type quickly.
That’s ok, sometimes I to to type quickly too
I seem to recall in an Operating Systems class we wrote a kernel module and communicated with it through the proc interface?
I may have been through “SysFS” as well? In
/sys/classyou can setup char dev IO with a kernel module (and more). Very helpful for userspace <-> kernel communication (like DMA drivers for userspace applications)Hmm yeah maybe it was /sys, it’s been so long I can’t remember.
I seem to recall echoing into a file to set some value which we then checked the value of in the kernel module code. It was just a hello world type of thing for a college class.
I know what a symlink is, but what is a magic symlink?
Also known as zombie files. If you are unlucky they can take up all space on a drive, or even tmpfs (so your ram) and you can’t easily find them. At least until you end the right process or restart.
Had that happen once and had to write my own script to trace it to the log of an open terminal emulator tab that had billions of lines.A symlink that has been blessed by Richard Stallman.

“Now that’s a name I haven’t heard in a long time” -Saint IGNUcius
If you delete a file that’s still open by the app, the link in proc will still exist and you can copy the file back out of proc.
Does that not make them a hard link (pointing to a filesystem node) instead of a symlink (pointing to another filename)?
No, you can’t have a hard link cross filesystems and proc is its own fs type.
Ah - it has its own special magical file system type, that’s the secret sauce. Neat!
/dev and /sys are the other two special ones
These days there can be a dozen virtual filesystems doing various stuff. If you ever want to get quite baffled, install a terminal emulator on an Android phone (not Termux) and run
mount.Remember the old days before /dev was its own virtual filesystem?
It still is! If you try and boot a kernel with nothing in /dev, you won’t get most of the kernel boot messages since /dev/console doesn’t exist. You need a basic set of device nodes in /dev before udev is started.
If you’re going to rsync a system to new hardware and exclude /dev /proc /sys, it’s better to setup a new mount of your / to a different directory and sync off that, so you get the underlying stuff without the cruft.
Subscribe.









