This question is NOT a duplicate of this question Find out current working directory of a running process?, because the writing directory can be different from the working directory.
For example, I start two processes by running
my_script.sh in ~/ twice (one right after another).
my_script.sh, I have made it to write the output to a folder whose name is a time stamp. Hence, despite the same working directory, the two processes actually write into different directories, say
~/1212_000003/. (the 1st process starts at 00:00:01 on Dec. 12 and the 2nd starts 2 seconds later)
The solution in the question linked returns me the same result
~/ for the two processes and thus fail my purpose.
How to do it?