How to display only a process and its descendant processes on htop?

Under Linux, you can do:

htop -p `pstree -p $PID | perl -ne 'push @t, /\((\d+)\)/g; END { print join ",", @t }'`

where $PID is the root process. This works as follows:

  1. The list of the wanted processes are obtained with pstree, using the -p option to list them with their PID.
  2. The output is piped to a Perl script that retrieves the PID's, using a regular expression (here, \((\d+)\)), and outputs them separated with commas.
  3. This list is provided as an argument of htop -p.

For other OS like Mac OS, you may need to adapt the regular expression that retrieves the PIDs.

Note: It is unfortunately not possible to update the list with new children that are spawn later, because once htop has been executed, one cannot do anything else. This is a limitation of htop (current version: 2.0.2).

Tags:

Htop