How to View Open Files for a Process in htop
This article provides a quick guide on how to inspect the open files
and network sockets associated with a specific, highlighted process
using the htop interactive process viewer in Linux. By
utilizing built-in shortcuts and integrating with the lsof
utility, htop allows system administrators and developers
to troubleshoot file locks, monitor resource usage, and analyze process
behavior directly from the terminal interface.
Prerequisites for Viewing Open Files
Before using this feature within htop, ensure that the
lsof (LiSt Open Files) utility is installed on your Linux
system. htop relies on this external command to fetch and
display the detailed list of files a process has opened.
You can install it via your package manager if it is missing:
- Ubuntu/Debian:
sudo apt install lsof - RHEL/CentOS/Fedora:
sudo dnf install lsof
Step-by-Step Guide to Using the lsof Shortcut
- Launch the utility by typing
htopin your terminal. - Use the Up and Down arrow keys to navigate through the process list and highlight the specific target process.
- Press the
lkey (lowercase L) on your keyboard.
htop will immediately open a separate, dedicated screen
displaying every open file descriptor, regular file, library, and
network socket currently held by that process.
Navigating the Open Files Screen
Once inside the open files view, you can manage and inspect the data using the following controls:
- Arrow Keys: Scroll vertically through the list of open files if it exceeds the screen height.
forF4(Filter): Type a specific keyword, directory path, or filename to narrow down the list and find specific files quickly.qorEsc: Exit the open files screen and safely return to the main interactivehtopprocess dashboard.