OpenBSD Journal

ps(1) gains support for tree-like display of processes

Contributed by rueda on from the forest-hugger dept.

Following a discussion on tech@, Job Snijders (job@), committed to ps(1) support for displaying the parent/child hierarchy of processes as an ASCII art tree:

Module name:	src
Changes by:	2022/09/01 15:15:54

Modified files:
	bin/ps         : extern.h print.c ps.1 ps.c ps.h 

Log message:
Add forest (-f) mode

In -f mode group & display parent/child process relationships using ASCII art.

Borrows heavily from Brian Somers' work on FreeBSD ps(1).

With input from deraadt@ and tb@

OK benno@ claudio@

The "-f" option letter is after GNU ps.

The first post in the tech@ thread gives an example of the appearance:

    $ ps ad -O ppid,user
    18180 12529 job      pb  I+p      0:00.01 `-- -sh (sh)
    26689 56460 job      p3  Ip       0:00.01   `-- -ksh (ksh)
     5153 26689 job      p3  I+p      0:40.18     `-- mutt
    62046 25272 job      p4  Sp       0:00.25   `-- -ksh (ksh)
    61156 62046 job      p4  R+/0     0:00.00     `-- ps -ad -O ppid
    26816  2565 job      p5  Ip       0:00.01   `-- -ksh (ksh)
    79431 26816 root     p5  Ip       0:00.16     `-- /bin/ksh
    43915 79431 _rpki-cl p5  S+pU     0:06.97       `-- rpki-client
    70511 43915 _rpki-cl p5  I+pU     0:01.26         |-- rpki-client: parser (rpki-client)
    96992 43915 _rpki-cl p5  I+pU     0:00.00         |-- rpki-client: rsync (rpki-client)
    49160 43915 _rpki-cl p5  S+p      0:01.52         |-- rpki-client: http (rpki-client)
    99329 43915 _rpki-cl p5  S+p      0:03.20         `-- rpki-client: rrdp (rpki-client)

This (great, convenience) feature was previously unavailable in the base system, but could be found in ports such as pstree(1).

(Comments are closed)

  1. By d.c. (d.c.) on

    Sounds really promising! After 'cp -a' doing 'ps axf' is my second most often mistake, when I keep digressing from OpenBSD to GNU/Linux and back many times a day...


Copyright © - Daniel Hartmeier. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Contents of the archive prior to as well as images and HTML templates were copied from the fabulous original with Jose's and Jim's kind permission. This journal runs as CGI with httpd(8) on OpenBSD, the source code is BSD licensed. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]