Sometimes I'm looking for an equivalent for the AIX proctree command which displays all children and all ancestors of a specified PID and can be sometimes quite useful for troubleshooting purposes. As an example here's an excerpt of the man page:

To display the ancestors and children of process 12312,
including children of process 0, enter:

   proctree -a 12312

The output of this command might look like this:
1    /etc/init                                  
   4954    /usr/sbin/srcmstr                    
      7224    /usr/sbin/inetd                   
         5958    telnetd -a                     
            13212    -sh                        
               14724    ./proctree -a 13212

Another useful form that I use sometimes is proctree $$ which will also show my current terminal, and whether I logged in via ssh or via console.

For clarification, I'm not looking for a script that emulates this on linux but an actual equivalent that may already be existent.

On linux, pstree shows all child processes of a specified PID, but the root will always be the specified PID (or init if no PID is specified and a complete tree will be shown).

Something like ps --forest -u "$username" does also not help as it only shows the processes of a given user, and it shows all of them - not only the ones of a given tree.


I think pstree -s 12312 gives what you want, if not in as nice a format.

  • Heh. Meanwhile, I totally missed that -a specifies (implies?) tree formatting. Thanks. :) – The Sidhekin Oct 8 '15 at 18:06
  • Yes, seems it does, that is also hidden in the man-page: [...] -a implicitly disables compaction for processes but not threads. – doktor5000 Oct 8 '15 at 18:12

Reposting my comment as an answer for better formatting.

Oh boy, seems I totally missed that in the man page. pstree -pas PID will show also parents, formatted as tree and include the PIDs of the processes.

An example:

[doktor5000@Mageia5]─[20:06:48]─[~] pstree -pas $$
          └─pstree,9595 -pas 9517

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.