The hand written effect make these so much easier to digest.
I never really considered using proc to solve my problems. I jump to logs and such but honestly, how have I never played with proc?
Julia Evans has such great and accessible content, they’re awesome

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!
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 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.
Thanks for explaining, I was wondering about that.
Wait, is that why renaming or moving files on android takes forever?
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 itselfThis 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
You used to be able to sudo cat /proc/kcore > /dev/dsp and listen to your ram
Wouldn’t that just sound like gibberish? I feel like Mike Lindell would come out of the speakers.
it rotated in between white noise, strobing sirens, digital corruption and silence.
Great tips! Although if i may 🤓 just a little for the top right, it works because what you deleted isn’t the binary, it’s the pointer that points to the binary’s location. The data is still exactly as it was before “deletion”; the symlink is simply a copy of the original pointer’s info; and I’m speculating that the existence of any pointer prevents the system from recycling those addressed bits.
I didn’t know any of this. Amazing. I usually just look at
/proc/net/for routes and bonding config etc.Do you know how to build portable executables?
configure --prefix=/proc/self/pwdIt even works in .so files and libtool.
May I have the explanation?
The executable will search for .so files not inside predefined paths like /usr/lib but inside it’s current directory. You may theoretically put
.as an argument toconfigure, but it converts that into an absolute path, snd libtool and linker fail when encountering relative paths inside shared library dependencies.Thank you
I would generally just set the RPATH to
$ORIGINin the ELF file
Julia Evans has a bunch of these really handy cheatsheets. I have several saved that I reference semi-regularly.
Did you know openBSD does not have this folder? I think the BSD’s do not use /proc. I do not know why though.
That raises the question of how their
ps,top,lsofand such work, since afaik in Linux they read from /proc.P.S. Looks like BSDs tug at the kernel via syscalls, namely
sysctland also the ‘kvm interface’ in the case of MacOS (not sure what ‘kvm’ thing is meant here). Seems vaguely reasonable, since procfs also queries the kernel for the info, so about the same resources would be used, perhaps even with the overhead of filesystem traversal and string-numbers conversion.I might be mistaken, but I think kvm stands for kernel virtual machine. Having no /proc, and interacting with sysctl instead sounds more secure, IMO.
Some pseudofiles under /proc are only readable by the user running the process, and of course root can read everything. So it’s the standard Unix security model, afaics.
For example, any process’ command-line arguments are famously visible to everyone, while the environment variables only to the user of the process.
Subscribe.
I am saving this, both for the post AND for the comments.
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