I have a program a.out running from /tmp/test. If I list /proc/$(pgrep a.out)/cwd
, it is a symbolic link to /tmp/test.
Now, I bind /mnt/othertest onto /tmp/test with mount -o bind /mnt/othertest /tmp/test
. Thus, this new mount is stacked and old /tmp/test is hidden.
Still, since a.out was launched before mount command, it has access to the old path.
The problem I want to tackle is how to know if a process with cwd set to /tmp/test refers to the directory from /mnt/othertest or not.
For opened files, it is easy, I can use fdinfo from proc pseudo-filesyste and read the mount id, but I did not find such information for cwd. I could check the start time of the process and compare it with the time when mount was launched, but because of possible forks it could be wrong.