linux equivalent to AIX proctree command to show all child and parent processes of a given PID

5,894

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

Share:
5,894

Related videos on Youtube

doktor5000
Author by

doktor5000

Mageia - the magic continues ...

Updated on September 18, 2022

Comments

  • doktor5000
    doktor5000 over 1 year

    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.

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