How is /proc/self implemented in Linux

procprocess

I was tinkering around with the /proc filesystem in Linux, and I came across /proc/self, which is a symbolic link to the process directory of the current process. I would like to know how it is implemented. One solution would be to change that symlink on every context switch, but that's obviously very expensive as it involves a disk access.

Best Answer

http://lxr.linux.no/linux+v3.2.9/fs/proc/base.c#L2482 is the current implementation.

The proc filesystem is entirely virtual, and is implemented so the internal VFS readlink delegates to the right place for special symlinks. So, it calculates what self points to when it is read / traversed, not every context switch.

Related Question