pwdx
Identify process's current working directory
TLDR
Print current working directory of a process
SYNOPSIS
pwdx PID
PARAMETERS
PID
The Process ID (PID) of the running process whose current working directory you want to query.
DESCRIPTION
The pwdx command is a utility used to determine the current working directory (CWD) of a specified running process. It takes a single argument, the Process ID (PID), and outputs the absolute path of the directory from which that process is currently operating. This can be particularly useful for debugging, system monitoring, or understanding the environment of an application.
Under the hood, pwdx achieves this by reading the symbolic link /proc/PID/cwd, which points to the process's current working directory. Since it relies on the procfs filesystem, it's highly efficient. It provides a quick way to inspect a process's environment without attaching a debugger or using more complex tools like lsof or strace.
CAVEATS
Access to a process's CWD via pwdx is subject to permissions. You can typically query processes owned by your user, but querying processes owned by other users or root often requires root privileges. If the specified PID does not exist, or if you lack sufficient permissions, pwdx will return an error.
The CWD of a process can change during its lifetime, so the output reflects the CWD at the moment pwdx is executed.
<B>UNDERLYING MECHANISM</B>
pwdx directly accesses the /proc pseudo-filesystem, which is a standard feature on Linux. For every running process with PID N, there's a directory /proc/N. Inside this directory, the cwd entry is a symbolic link pointing to the process's current working directory. pwdx simply resolves this symlink. This mechanism is fast and lightweight as it avoids scanning system calls or large amounts of data.
HISTORY
The pwdx command is part of the procps-ng suite of utilities, which provides various tools for monitoring and interacting with processes on Linux systems by leveraging the /proc filesystem. It was developed as a convenient wrapper around reading the /proc/PID/cwd symlink, simplifying a common diagnostic task for system administrators and developers.