Using tools such as ps or top, you are able to see the processes running on a machine. However, you can’t see the directory from which the process was started. Knowing the working directory can be useful if, for example, you need to move a script or program to stop a fork bomb, if you want to see where a script or program lives or, if a script or program reads files using a relative path, to see which files are being read.

This working directory can be found using the pwdx <pid> [<pid> ...] utility. For example, consider the following output from ps:

everyone  2646     1  2 21:21 ?        00:00:00 terminal
everyone  2651  2646  0 21:21 pts/0    00:00:00 bash

We can see that terminal and bash are running, but we don’t know where these processes were started. Using pwdx, we can easily find out:

$ pwdx 2646 2651
2646: /home/everyone
2651: /home/everyone