Linux has a /proc directory and file‑system, which as far as I can tell, is not part of POSIX. In each /proc/$PID subdirectories, is a symbolic link, cwd, pointing to the actual working directory of the process of this PID (the cwd link is always up to date).
This symbolic link is convenient for some use case, like working with distinct shells and exchanging files between the two shells (formally, their working directories).
Is there a simple way to get something similar, only using POSIX feature?
More on the question
After a comment, more precision: it does not have to necessarily be a link and an environment variable lile $<PID>_CWD, would be as much fine too, although at first sigh, I don't believe such a solution exist. It just has to be easy to refer to (ex. symbolic link or environment variable) and be always up to date each time the other process switch it's working directory.
The solution does not need to necessarily be POSIX, and the most important aspect is portability, but POSIX is surely a guarantee.
pwdxcommand, so you may just create an alias or function calledpwdxon Linux that wraps aroundreadlinkif you're looking for something portable.pwdxcommand that comes withprocpsso that may be your answer.pwdx. But FreeBSD doesn't.getcwd(3)used to work by callingstat(".")andreaddir(".."), finding a matching inode number, and repeating the process upward until it hit the root directory. Good luck doing that in the context of another process. (I suppose one could useptraceto inject a call togetcwd...)