Table of Contents
Ubuntu - Processes - Inspect the current working directory of a running process
Objective
To inspect the current working directory of a running process
Scenario
Suppose that you wish to check that a daemon called exampled is executing in the intended working directory (that being /var/lib/exampled).
It has a process ID of 29964.
Method
The current working directory of any process can be displayed using the pwdx command.
On Debian-based systems this can be found in the procps package, which is usually installed by default.
pwdx is invoked with a list of one or more process IDs to be inspected:
pwdx 29964
The resulting output should be of the form:
29964: /var/lib/exampled
Be warned that the pwdx command in Debian Lenny has a bug that makes it unusable.
This was not present in Etch and is fixed in Squeeze. There is a similar problem in Ubuntu Jaunty, which is fixed in Karmic.
If you need the functionality of pwdx on one of these systems then see the alternative method described below.
The behavior when pwdx and/or the inspected process are running inside a chroot does not appear to be documented.
Errors
Cannot find /proc/version
An error of the form:
Cannot find /proc/version - is /proc mounted?
probably indicates, as the message suggests, that /proc has not been mounted.
See Mounting /proc for further guidance.
Alternative
Obtain the working directory pathname from /proc
An alternative method for inspecting the working directory is to obtain the information directly from /proc.
It is presented as a softlink called cwd:
ls -l /proc/29964/cwd
The working directory of the process is the target of the softlink:
lrwxrwxrwx 1 root root 0 Feb 6 15:57 cwd -> /var/lib/exampled