Page MenuHomeFreeBSD

fix `ps -aa`

Authored by on Nov 14 2020, 6:00 AM.
Referenced Files
Unknown Object (File)
Tue, Sep 5, 8:21 PM
Unknown Object (File)
Aug 14 2023, 5:39 PM
Unknown Object (File)
Aug 14 2023, 5:02 AM
Unknown Object (File)
Jul 30 2023, 9:57 AM
Unknown Object (File)
Jul 8 2023, 9:31 AM
Unknown Object (File)
Jul 8 2023, 9:29 AM
Unknown Object (File)
Jul 8 2023, 9:26 AM
Unknown Object (File)
Jul 4 2023, 5:11 AM



Passing the -a flag multiple times make ps show no processes.

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable

Event Timeline

pstef added a subscriber: pstef.

Looks good to me.

This revision is now accepted and ready to land.Sep 23 2021, 5:11 PM

I thought about this more and I have a question. What should the result of ps -uxaa -U $(id -un) be? Should it only list my processes (-U) or all of them (-a)? I think we might need an additional change like this:

diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index f23b3c52735..f8dcd3cfa02 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -512,7 +512,9 @@ main(int argc, char *argv[])
        what = showthreads != 0 ? KERN_PROC_ALL : KERN_PROC_PROC;
        flag = 0;
-       if (nselectors == 1) {
+       if (all)
+               nselectors = 0;
+       else if (nselectors == 1) {
                if (gidlist.count == 1) {
                        what = KERN_PROC_RGID | showthreads;
                        flag = *gidlist.l.gids;

Hard to say. It would make sense and IIUC it's what Linux does (though there are other incompatibilities there already and it treats options with an without dashes differently (its -a excludes session leaders for some reason, but the "BSD style" option without dash does not)).

But it would change the current behavior and other BSDs don't do it.

Currently -a just changes what ps does by default, it's not really a "selector" that does a union like the rest. And -x is a filter on top of that. That's useful if you want to alias "ps" (or something else) to "ps -ax" so that it just stops hiding processes by default and still use it with other selector arguments (that's how I noticed the problem with repeated -a because I kept using it out of habit).

This revision was automatically updated to reflect the committed changes.