How to View Process Working Directory in htop Ubuntu
This article explains how to determine the current working directory
of a running process on Ubuntu using htop. While
htop does not display this path directly within its
interface, it is the most efficient tool for locating the specific
Process ID required to retrieve the information. The steps below detail
how to extract the PID from htop and use standard terminal
commands to reveal the directory.
Identify the Process ID in htop
Launch htop in your terminal by typing htop
and pressing Enter. Use the arrow keys to navigate through the list of
running processes until you highlight the specific process you are
investigating. Look at the PID column on the left side
of the screen to find the Process ID number associated with that task.
Note this number down or keep it in mind, then exit htop by
pressing q or switch to a new terminal window while leaving
htop running.
Retrieve the Directory Path
Open your terminal and use the Linux /proc filesystem to
access the process details. Run the following command, replacing
<PID> with the number you identified in
htop:
ls -l /proc/<PID>/cwdThis command lists the symbolic link for the current working
directory of the process. The output will show an arrow pointing to the
absolute path, such as /home/user/projects. This path
represents the directory from which the process was executed or where it
is currently anchored.
Alternative Method Using pwdx
You can also use the pwdx command, which is designed
specifically to print the current working directory of a process. This
method is often faster to type and provides a cleaner output. Enter the
following command in your terminal:
pwdx <PID>The terminal will return the PID followed by the full path of the
working directory. Both methods rely on the PID found in
htop to accurately locate the directory information that
htop does not show natively.