pstack – Displays the stack trace for each process

The pstack command is a Linux utility that displays the stack trace for each process. It is used to diagnose and debug the running processes on a Linux system. This command is useful when a process is not responding or behaving unexpectedly.

Overview

To use the pstack command, simply type pstack followed by the process ID (PID) of the process you want to examine. The command will then display the stack trace for that process.

pstack [options] pid

Examples

pstack 1234

This will display the stack trace for the process with PID 1234.

Specific use cases

  • Debugging a process that is not responding or behaving unexpectedly.
  • Analyzing the execution flow of a process.

Options

The following table lists all available options for the pstack command:

Option Description
-h Display help message and exit
-V Display version information and exit
-f Display the stack trace for all threads in the process
-p Attach to a running process using its PID
-u Display the user name and ID of the process owner

Troubleshooting tips

  • If the pstack command does not display any output, ensure that the process ID (PID) is correct and that the process is running.
  • If the command displays an error message, ensure that you have sufficient permissions to access the process.

Notes

  • The pstack command is included in the procps-ng package, which is typically pre-installed on most Linux systems.
  • The stack trace displayed by the pstack command is generated by reading the process’s memory and interpreting the contents of the stack. As a result, it may not always be accurate or complete.