Page MenuHomeFreeBSD

fix `ps -aa`
ClosedPublic

Authored by sigsys_gmail.com on Nov 14 2020, 6:00 AM.

Details

Summary

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

Diff Detail

Repository
rG FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit 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.