I was wandering on the Linux filesystem, which looks like a good way of understanding how it works. In UNIX "everything is a file", so I was looking at /dev/stdin
and noticed it is a soft link to /proc/self/fd/0
. So I decided to go take a look at the /proc
folder, finding that /proc/self
is actually a soft link to /proc/{PID}
. To be more precise, the PID is the one of the ls -l /proc/self
command I issue to check its value.
My theory is that the soft link is changed everytime a program tries to read it, to point to the right PID process folder. Is this done by the kernel on every request it gets to read the /proc
folder? I don't think you need to actually read the file to get the output of ls
or we wouldn't be able to see files with 700 permission, so does the soft link change happens when the /proc
folder is accessed?
Going even further: Is this kind of control restricted for the kernel itself or can some applications make use of that? (Maybe checking when a folder is being accessed to dynamically change its contents/links according to "who" is doing it)