[RFC] Extending the format of ps
"Craig Small" <[email protected]> ("csmall") Fri, 1 Sep 2023 17:29:58 +1000
| Newsgroups | gmane.linux.procps.devel |
|---|---|
| Message-ID | <CALy8Cw4yf8bmBXH2KBHthTrGEuhTjJLBUaPPfGTkOFMeNL+CFQ@mail.gmail.com> |
--000000000000697428060447217d
Content-Type: text/plain; charset="UTF-8"
Hello All,
This is prompted by a StackExchange comment at
https://unix.stackexchange.com/questions/755316/introduce-literal-strings-in-ps-command
The interesting thing is, that AIX format types used to work for ps. So you
would get things like:
ps --format 'foo %c bar'
foo COMMAND bar
foo bash bar
Here foo and bar are string literals and %c is an AIX format (equivalent to
-o 'comm').
That got removed in
https://gitlab.com/procps-ng/procps/-/commit/8cb646bdfc6e37b221f9616df96c6c116e6def28
which references
https://gitlab.com/procps-ng/procps/-/commit/81df85a1b528d4edb9ab98b37fb6c6244430b6c4
and
https://www.freelists.org/post/procps/Procpsng-400-released-with-newlib,2
So we do have a nice sane(ish) setup, the oddballs being %cpu (is this BSD
-o pcpu or is it AIX "%c pu" ?) as exceptions. The old AIX behaviour looks
reasonably easy to fix; line 145 in ps/sortformat.c change from goto
aix_oops to get_more.
So that's one idea, I haven't been able to get the parser to choke though
there are some nits like -o %cpu is BSD format "pcpu" but %cpux is AIX
format "comm pux". There are only 15 fields that AIX format has, so a lot
of fields go missing and the maximum might be 52 items (upper and lowercase
letters).
Another is, should there be a way of putting string literals in ps? I think
if this was wanted then:
1) It should be a completely different option, the format options switch
modes already so adding any more complexity to their parsers would be
difficult.
2) It should handle all the fields, probably BSD fields with an escape
(maybe % because thats the usual one).
So you could do things like:
ps --printf 'blah %pid %pcpu %comm end'
blah PID %CPU COMMAND end
blah 49642 0.0 bash end
blah 73077 0.0 vi end
blah 74158 0.0 ps end
Another idea might be to use the standard -o/-O options but have a way of
making literals escaped. e.g. ps -o {blah},pid,pcpu,comm,{end}
Or it could be left the way it is.
- Craig
--
Craig Small https://dropbear.xyz/ csmall at : dropbear.xyz
Debian GNU/Linux https://www.debian.org/
<http://www.debian.org/> csmall at : debian.org
GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5
--000000000000697428060447217d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Hello All,</div><div>=C2=A0 This is prompted by a Sta=
ckExchange comment at <a href=3D"https://unix.stackexchange.com/questions/7=
55316/introduce-literal-strings-in-ps-command">https://unix.stackexchange.c=
om/questions/755316/introduce-literal-strings-in-ps-command</a></div><div><=
br></div><div>The interesting thing is, that AIX format types used to work =
for ps. So you would get things like:</div><div>ps --format 'foo %c bar=
'<br>foo COMMAND =C2=A0 =C2=A0 =C2=A0 =C2=A0 bar<br>foo bash =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bar<br></div><div><br></div><div>Here foo an=
d bar are string literals and %c is an AIX format (equivalent to -o 'co=
mm').</div><div>That got removed in <a href=3D"https://gitlab.com/procp=
s-ng/procps/-/commit/8cb646bdfc6e37b221f9616df96c6c116e6def28">https://gitl=
ab.com/procps-ng/procps/-/commit/8cb646bdfc6e37b221f9616df96c6c116e6def28</=
a></div><div>=C2=A0</div><div>which references</div><div><a href=3D"https:/=
/gitlab.com/procps-ng/procps/-/commit/81df85a1b528d4edb9ab98b37fb6c6244430b=
6c4">https://gitlab.com/procps-ng/procps/-/commit/81df85a1b528d4edb9ab98b37=
fb6c6244430b6c4</a></div><div>and</div><div><a href=3D"https://www.freelist=
s.org/post/procps/Procpsng-400-released-with-newlib,2">https://www.freelist=
s.org/post/procps/Procpsng-400-released-with-newlib,2</a></div><div><br></d=
iv><div>So we do have a nice sane(ish) setup, the oddballs being %cpu (is t=
his BSD -o pcpu or is it AIX "%c pu" ?) as exceptions. The old AI=
X behaviour looks reasonably easy to fix; line 145 in ps/sortformat.c chang=
e from goto aix_oops to get_more.<br></div><div><br></div><div>So that'=
s one idea, I haven't been able to get the parser to choke though there=
are some nits like -o %cpu is BSD format "pcpu" but %cpux is AIX=
format "comm pux". There are only 15 fields that AIX format has,=
so a lot of fields go missing and the maximum might be 52 items (upper and=
lowercase letters).<br></div><div><br></div><div>Another is, should there =
be a way of putting string literals in ps? I think if this was wanted then:=
</div><div>1) It should be a completely different option, the format option=
s switch modes already so adding any more complexity to their parsers would=
be difficult.</div><div>2) It should handle all the fields, probably BSD f=
ields with an escape (maybe % because thats the usual one).</div><div>So yo=
u could do things like:</div><div>ps --printf 'blah %pid %pcpu %comm en=
d'</div><div>blah=C2=A0 =C2=A0 PID %CPU COMMAND end</div><div>blah =C2=
=A0 49642 =C2=A00.0 bash end<br>blah =C2=A0 73077 =C2=A00.0 vi end<br>blah =
=C2=A0 74158 =C2=A00.0 ps end<br></div><div><br></div><div>Another idea mig=
ht be to use the standard -o/-O options but have a way of making literals e=
scaped. e.g. ps -o {blah},pid,pcpu,comm,{end}</div><div><br></div><div>Or i=
t could be left the way it is.</div><div><br></div><div>=C2=A0- Craig</div>=
<div><br></div><div><br></div><span class=3D"gmail_signature_prefix">-- </s=
pan><br><div dir=3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gmail_=
signature"><div dir=3D"ltr"><pre>Craig Small <a href=3D"https:/=
/dropbear.xyz" target=3D"_blank">https://dropbear.xyz/</a> csmall at : <a =
href=3D"http://dropbear.xyz" target=3D"_blank">dropbear.xyz</a>
Debian GNU/Linux <a href=3D"http://www.debian.org/" target=3D"_blank=
">https://www.debian.org/</a> csmall at : <a href=3D"http://debian.org" ta=
rget=3D"_blank">debian.org</a>
GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5</pr=
e></div></div></div>
--000000000000697428060447217d--