
# This could be generalized to a lot of other things. # Use gdb to change the working directory of a process from outside. Not all programs appreciate having their current directory changed under their feet - for example a shell is likely to crash. This is useful for example to move a long-running program that doesn't care about its current directory out of a directory that you want to remove. Lsof -p $pid | awk '$4="cwd" 'īonus: if you need to cause a process to change its current directory, you can do it with a debugger. If you feel lucky, you can use the second form, which silently chokes on all whitespace in the directory name. Beware that if there is a newline, it will be printed as \n (indistinguishable from backslash followed by n). On just about any unix variant, you can use lsof. On Linux (except embedded systems where readlink is not available) but not Solaris: readlink /proc/$pid/cwd



On Linux and Solaris and perhaps some other System V unices: cd /proc/$pid/cwd & pwd Most methods on most systems will require that the shell you're doing this from is running as the same user as the target process (or root). I assume that you have the process ID in pid.
