1

About the ps command - to add one/many extra column/header with the default headers according with the option(s) used with the ps command - it through O the option.

Intro

If ps x is executed the output is as follows:

  PID TTY      STAT   TIME COMMAND
 1677 ?        Ss     0:00 /lib/systemd/systemd --user
 1679 ?        S      0:00 (sd-pam)
 1704 tty1     S+     0:00 -bash
 1961 tty4     S      0:00 -bash
 1973 tty4     S+     0:00 man ps
 1983 tty4     S+     0:00 pager
 2227 ?        S      0:00 sshd: manueljordan@pts/0
 2228 pts/0    Ss     0:00 -bash
 2307 ?        S      0:01 sshd: manueljordan@pts/1
 2308 pts/1    Ss     0:00 -bash
 2407 ?        S      0:00 sshd: manueljordan@pts/2
 2408 pts/2    Ss     0:00 -bash
 2437 pts/2    S+     0:00 less
 2846 pts/1    S+     0:00 man ps
 2856 pts/1    S+     0:00 pager
 2968 pts/0    R+     0:00 ps x 

Appears and we know the default set of column/headers.

How a simple confirmation - if ps xO %cpu is executed the output is as follows:

  PID %CPU S TTY          TIME COMMAND
 1677  0.0 S ?        00:00:00 systemd
 1679  0.0 S ?        00:00:00 (sd-pam)
 1704  0.0 S tty1     00:00:00 bash
 1961  0.0 S tty4     00:00:00 bash
 1973  0.0 S tty4     00:00:00 man
 1983  0.0 S tty4     00:00:00 pager
 2227  0.0 S ?        00:00:00 sshd
 2228  0.0 S pts/0    00:00:00 bash
 2307  0.0 S ?        00:00:01 sshd
 2308  0.0 S pts/1    00:00:00 bash
 2407  0.0 S ?        00:00:00 sshd
 2408  0.0 S pts/2    00:00:00 bash
 2437  0.0 S pts/2    00:00:00 less
 2846  0.0 S pts/1    00:00:00 man
 2856  0.0 S pts/1    00:00:00 pager
 2969  0.0 R pts/0    00:00:00 ps

Until here all is ok. No reason to create this post

Therefore theoretically can be added any HEADER based on with its respective CODE - it according with the STANDARD FORMAT SPECIFIERS section, it available through man ps.

Now thanks with the experience of this question:

Appears the PSR column/header.

Situation

If ps xO psr is executed the output is as follows:

  PID TTY      STAT   TIME COMMAND
 1677 ?        Ss     0:00 /lib/systemd/systemd --user
 1679 ?        S      0:00 (sd-pam)
 1704 tty1     S+     0:00 -bash
 1961 tty4     S      0:00 -bash
 1973 tty4     S+     0:00 man ps
 1983 tty4     S+     0:00 pager
 2227 ?        S      0:00 sshd: manueljordan@pts/0
 2228 pts/0    Ss     0:00 -bash
 2307 ?        S      0:01 sshd: manueljordan@pts/1
 2308 pts/1    Ss     0:00 -bash
 2407 ?        S      0:00 sshd: manueljordan@pts/2
 2408 pts/2    Ss     0:00 -bash
 2437 pts/2    S+     0:00 less
 2846 pts/1    S+     0:00 man ps
 2856 pts/1    S+     0:00 pager
 2975 pts/0    R+     0:00 ps xO psr

If you realize the PSR does not appear, why?

But if ps xO %cpu,psr is executed the output is:

  PID %CPU PSR S TTY          TIME COMMAND
 1677  0.0   1 S ?        00:00:00 systemd
 1679  0.0   2 S ?        00:00:00 (sd-pam)
 1704  0.0   1 S tty1     00:00:00 bash
 1961  0.0   0 S tty4     00:00:00 bash
 1973  0.0   1 S tty4     00:00:00 man
 1983  0.0   2 S tty4     00:00:00 pager
 2227  0.0   3 S ?        00:00:00 sshd
 2228  0.0   3 S pts/0    00:00:00 bash
 2307  0.0   3 S ?        00:00:01 sshd
 2308  0.0   3 S pts/1    00:00:00 bash
 2407  0.0   0 S ?        00:00:00 sshd
 2408  0.0   0 S pts/2    00:00:00 bash
 2437  0.0   0 S pts/2    00:00:00 less
 2846  0.0   0 S pts/1    00:00:00 man
 2856  0.0   0 S pts/1    00:00:00 pager
 2981  0.0   0 R pts/0    00:00:00 ps

or if ps xO uname,psr is executed the output is:

  PID USER     PSR S TTY          TIME COMMAND
 1677 manuelj+   1 S ?        00:00:00 systemd
 1679 manuelj+   2 S ?        00:00:00 (sd-pam)
 1704 manuelj+   1 S tty1     00:00:00 bash
 1961 manuelj+   0 S tty4     00:00:00 bash
 1973 manuelj+   1 S tty4     00:00:00 man
 1983 manuelj+   2 S tty4     00:00:00 pager
 2227 manuelj+   3 S ?        00:00:00 sshd
 2228 manuelj+   3 S pts/0    00:00:00 bash
 2307 manuelj+   3 S ?        00:00:01 sshd
 2308 manuelj+   3 S pts/1    00:00:00 bash
 2407 manuelj+   0 S ?        00:00:00 sshd
 2408 manuelj+   0 S pts/2    00:00:00 bash
 2437 manuelj+   0 S pts/2    00:00:00 less
 2846 manuelj+   0 S pts/1    00:00:00 man
 2856 manuelj+   0 S pts/1    00:00:00 pager
 2982 manuelj+   0 R pts/0    00:00:00 ps

How you can see when is declared at least another extra header to be added together with the PSR header, just then/only PSR appears in the output.

Why the PSR header does not appear when is declared how the unique extra header to be added through the O option? Is it an expected behavior for some reason?

1
  • 2
    Well, the man page for the procps-ng 3.3.16 implementation says of O that it is "(overloaded)" and that "Heuristics are used to determine the behavior of this option." - my guess is that the heuristic in this case identifies Opsr as a sort option with a set of OBSOLETE SORT KEYS, rather than as a "user-defined output format with some common fields predefined". Commented May 7, 2022 at 12:10

1 Answer 1

2

I'd recommend not using the O option like that because it can lead to confusion because it behavior changes depending on what fields it gets and quite often it is very confusing.

So you probably see ps xO psr and think that means it should sort and show the PSR (last processor used) column?

It's not doing that actually.

@steeldriver above nailed it, it's sorting with the old keys. So you are asking ps to sort by: pid "p", size "s" and RSS "r". Sorting by rsp or spr are just as valid, with different order of sorting of course.

Why does ps xO psr,%cpu or even for that matter ps xO psr,psr change things? ps now realises you don't want the old sort keys and are using the name of columns to sort.

1
  • I didn't know about the old keys, and I expected the same behavior with 1 or 2 columns. So due this strange behavior with just 1 column and by coincidence for the PSR column I created this post Commented May 10, 2022 at 13:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.