pwdx

This handy little utility comes from the same family as the venerable ps utility we all know and love. The pwdx utility will allow you to get the current working directory of a running process. All you need to do is pass it the PID and then it will tell you where that process is working from.

Let’s say we wanted to find out where the cron process was working from on our machine. First we just need to figure out the PID by searching for it using ps like so:

ps aux | grep cron  
  
> root   612  0.0  0.0   7260  2708 ?  Ss   May06   0:11 /usr/sbin/cron -f

Here we can see that the PID of cron is 612. Now all we need to do is determine the working directory of that process by passing it to pwdx like this:

sudo pwdx 612  
  
> 612: /var/spool/cron

Since cron is a system process, you must sudo in order to obtain information about it. Once the command completes we’re left with the current working directory of cron, which is /var/spool/cron.

This can be a very valuable troubleshooting tool, especially if you’re chasing down directory scoping issues. A quick check with pwdx and you can figure out exactly where a process thinks it should be running from.

Check out the man page for pwdx here.