Inspect the current working directory of a running process
|Debian (Etch, Squeeze)|
|Ubuntu (Hardy, Intrepid, Karmic, Lucid, Maverick, Natty, Precise, Trusty)|
To inspect the current working directory of a running process
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.
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:
The resulting output should be of the form:
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 behaviour when
pwdx and/or the inspected process are running inside a
chroot does not appear to be documented.
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.
An alternative method for inspecting the working directory is to obtain the information directly from
/proc. It is presented as a softlink called
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