Page MenuHomeFreeBSD

fix `ps -aa`
ClosedPublic

Authored by sigsys_gmail.com on Nov 14 2020, 6:00 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 11, 4:52 PM
Unknown Object (File)
Sun, Dec 1, 12:47 PM
Unknown Object (File)
Nov 8 2024, 6:08 AM
Unknown Object (File)
Nov 8 2024, 5:48 AM
Unknown Object (File)
Nov 8 2024, 3:06 AM
Unknown Object (File)
Oct 21 2024, 7:29 AM
Unknown Object (File)
Oct 21 2024, 6:40 AM
Unknown Object (File)
Oct 21 2024, 6:40 AM

Details

Summary

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

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
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.