topunix / pst

:deciduous_tree: A reproduction of pstree
Other
0 stars 0 forks source link

not working as expected when ppid greater than pid #6

Open joknarf opened 3 years ago

joknarf commented 3 years ago

When child pid less than its parent, the ps command will display child before parent (see 375 1051 bash line in example)

it seems bad supposition in format_process_trees :

# Parent always comes before child
# ps -ef -o pid,ppid,args
  PID  PPID COMMAND
    1     0 /init
    6     1 /init
    7     6 /init
    8     7 -bash
  375  1051 bash
  383   375 bash
  396   383 ps -e -o pid,ppid,args
  636     1 /init
  637   636 /init
  638   637 -bash
 1011     8 bash
 1019  1011 bash
 1027  1019 bash
 1035  1027 bash
 1051  1035 bash

# ./pst.py -w
  PID  COMMAND
    1  /init
    6   \_ /init
    7   \_ /init
    8   |       \_ -bash
 1011   |           \_ bash
 1019   |               \_ bash
 1027   |                   \_ bash
 1035   |                       \_ bash
 1051   |                           \_ bash
  636   \_ /init
  637   \_ /init
  638           \_ -bash
  375  bash                                 <====== is child of 1051 !
  383   \_ bash
  392   \_ python ./pst.py -w
  393           \_ ps -e l

# pstree -ap
init,1
  ├─init,6
  │   └─init,7
  │       └─bash,8
  │           └─bash,1011
  │               └─bash,1019
  │                   └─bash,1027
  │                       └─bash,1035
  │                           └─bash,1051
  │                               └─bash,375
  │                                   └─bash,383
  │                                       └─pstree,407 -ap
  ├─init,636
  │   └─init,637
  │       └─bash,638
  └─{init},5
topunix commented 3 years ago

Thanks, I will take a look, when I have a chance. I appreciate your reports.