pstree command in linux with example

it pastry The Commands Guide is a follow-up to my previous 90 Linux Commands Frequently Used by Linux Sysadmins article. Every week, or as time permits, I will publish articles on ~90 commands geared to Linux sysadmins and Linux power users. let’s continue this series pstree Permission.

pstree commands and examples

Pstree is a convenient Linux command used to display running processes in a tree (data structure). If a username is specified, all process trees contained on processes owned by that user are shown. Pstree is used as an alternative to the ps command. The pstree command is commonly included in Linux distributions. Otherwise, it can be installed using psmisc For example, package yum install psmisc,

pstree command example:

The basic syntax for pstree is:

pstree [options] [pid or username]

To display all process trees contained on processes owned by a specific user, along with their PIDs, use:

pstree -p username

To display a tree of processes, use:

pstree

To display a tree of processes with PIDs, use:

pstree -p

To sort processes by PID instead of name, use:

pstree -np

To wrap long lines, use:

pstree -l

pstree alternatives (man pstree)

-a Show command line arguments. If the command line of a process is swapped, that process is shown in parentheses. -a Disables compaction for processes but not threads.
-A Use ASCII characters to draw the tree.
-c Disable compaction of the same subtree. By default, subtrees are collapsed whenever possible.
-C Color the process name by a given attribute. currently, pstree Accepts only the value age that colors according to the process age. New processes over 60 seconds are green, new ones over an hour are yellow and the rest red.
-g Show pgid. Process group IDs are shown as decimal numbers in parentheses after each process name. -g Indirectly disables compaction. If both PID and PGID are displayed then PID is shown first.
-G VT100 Use line-drawing characters.
-h Throw light on the present process and its ancestors. This is a no-op if the terminal does not support highlighting or if neither the current process nor its ancestors are being shown in the subtree.
-H Like -h , but highlight the specified process instead. opposite of this -h, pstree fails when using -H If highlighting is not available.
-l Display/wrap long lines. By default, rows are truncated to either the COLUMNS environment variable or the display width. If none of these methods work, the default of column 132 is used.
-n Sort processes with identical parents by PID instead of Name. (Numerical type.)
-N Show separate trees for each namespace of the specified type. Available types are IPC, MNT, NAT, PID, TIME, USER, UTS.
-p Show PID. The PID is shown as a decimal number in parentheses after each process name. -p indirectly disables compaction.
-s Show parent processes of the specified process.
-S Show namespace transitions. to like -NOutput is limited when run as a regular user.
-t Show full names for threads when available.
-T Hide threads and show only processes.
-u Show uid transition. Whenever the UID of a process is different from the UID of its parent, the new UID is shown in parentheses after the process name.
-U Use UTF-8 (Unicode) line drawing characters. Under Linux 1.1-54 and above, UTF-8 mode on the console is entered with echo -e ' 33%8' and left with echo -e' 33%@',
-V Display version information.
-Z Show current security characteristics of the process. For SELinux systems, this would be the security context.

pastry example

Pstree makes it very easy to find native processes. The root of the tree is either init or process with the given PID. as a reminder, psmisc The package contains a small set of utilities that use the proc file-system: fuser, kill all, prestat, pslog, peekfd, And yes pastry

Pastry Useful Reading:

pstree optional/related commands:

  • PS – Information about currently running processes.
  • alsosofe – List Open Files – Display any open file.
  • Top – Shows an overall system view.
  • PGREP – Find the process ID of the running program.

Leave a Comment