How to find the current working directory of a process…

Ok, this might sound insane, but this is the type of question you get asked sometimes, or the situation where you need to know comes up.

I was once asked what the current working directory was of a process on the server… often times I don’t even think about it, however the script was writing files, and we had no idea where ;)

I tracked it down to a pretty simple method

> ps -awux | grep [process]

root 90 0.0 0.0 1016 228 ?? Is 27Apr05 1:01.81 /usr/sbin/cron

> ls -l /proc/[pid from above, which is 90]/cwd

lrwxrwxrwx 1 root root 0 Nov 4 12:56 /proc/90/cwd -> /var/spool

And it’s current working directory is /var/spool

Neat :)

Leave a Comment