How to Trace System Calls with htop and strace?

Monitoring a running process in Linux often requires identifying the exact system calls it makes to the kernel. While strace is the standard command-line utility for this task, navigating process IDs (PIDs) manually can be cumbersome. The htop interactive process viewer solves this by allowing users to select any running process from a real-time visual list and immediately attach strace with a single keystroke. This article provides a quick guide on how to configure, initiate, and navigate system call tracing directly from within the htop interface.

Prerequisites and Permissions

Before using strace inside htop, you must ensure both utilities are installed and that your user account has the necessary permissions to attach to running processes.

Initiating strace from htop

Once the prerequisites are met, launching the trace takes only a few keystrokes.

  1. Launch htop: Open your terminal and start the utility by typing sudo htop.
  2. Locate the Target Process: Use the arrow keys to scroll through the process list, or press F3 (or /) to open the search bar and type the name of the process you want to monitor.
  3. Trigger the Trace: Highlight the desired process and press s on your keyboard.

The htop interface will immediately pause and open a nested window displaying a live feed of the system calls, arguments, and return values generated by the selected process.

The embedded strace view inside htop provides basic controls to analyze the output in real time without cluttering your terminal history.