Re: Basic ps Tips

Liste des GroupesRevenir à cu shell 
Sujet : Re: Basic ps Tips
De : joerg-mertens (at) *nospam* t-online.de (Joerg Mertens)
Groupes : comp.unix.shell
Date : 04. Aug 2024, 13:01:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v8nn26$1252$1@jmertens.eternal-september.org>
References : 1 2 3 4 5 6 7 8
User-Agent : tin/2.6.2-20221225 ("Pittyvaich") (OpenBSD/7.5 (amd64)) tinews.pl/1.1.61
Rene Kita <mail@rkta.de> wrote:
Joerg Mertens <joerg-mertens@t-online.de> wrote:
Rene Kita <mail@rkta.de> wrote:
 
I'm pretty sure I know which version of BSD I'm running and I would be
very surprised if OpenBSD would ship the FreeBSD version of ps...
 
But let's have a look at the source:
#v+
        while ((ch = getopt(argc, argv,
            "AaCcefgHhjkLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1)
                switch (ch) {
                case 'A':
                        all = 1;
                        xflg = 1;
                        break;
                case 'a':
                        all = 1;
                        break;
                case 'C':
                        break;                  /* no-op */
#v-
 
'-C' does nothing. I did not look further to see where that error is
coming from.
 
The error message also is printed, when you run ps with a valid
flag plus some string, like `ps -a xyz´, so it seems to be independent
of the `-C´-option.  Maybe it has to do with parsing of the old-style
flags vs. the dashed ones.
 
You got me curious and I got my debugger out for my morning coffee.
 
The error message comes from a function kvm_openfiles, which is called
after the flag parsing is done. From a quick glance, this function takes
what looks like three file names. If the second one is NULL, it will
default to /dev/mem. Trying to open /dev/mem it will error out - which
could be due to me being on a VPS.
 
While the man page mentions kvm(3) in the SEE ALSO section, there is no
mentioning nor explanation what additional arguments can be passed to
ps.

As I understand it, `ps´ can not only be used to examine the processes
of your currently running system, but also those of another system
represented by an image file.  Normally you would use the `N´ option
plus a filename to tell ps to do this, but the original way seems to
have been to just add the filename to the commandline as an additional
argument.

Now when you call `ps xy´, the argument xy is interpreted as a string
of old style options which can be written without dashes.  Some
people still write `ps aux´ for example to look at their processes.

But when you write `ps a xy´ (or `ps -a xy´), xy is interpreted as
a "kernel image to be examined" (see the first argument to
kvm_openfiles(3)), which leads to the `permission denied´ error.

To get back to the `-C´ option - it is there for compatibility
reasons with old scripts.  You can find the relevant commit message
under http://cvsweb.openbsd.org/src/bin/ps/ps.c when you search for the
string `-C´.

Joerg

Date Sujet#  Auteur
27 Jul 24 * Basic ps Tips22Lawrence D'Oliveiro
30 Jul 24 `* Re: Basic ps Tips21Lawrence D'Oliveiro
2 Aug 24  `* Re: Basic ps Tips20Jerry Peters
2 Aug 24   +- Re: Basic ps Tips1Lawrence D'Oliveiro
3 Aug 24   `* Re: Basic ps Tips18Rene Kita
3 Aug 24    +* Re: Basic ps Tips14Ed Morton
3 Aug 24    i`* Re: Basic ps Tips13Rene Kita
3 Aug 24    i +* Re: Basic ps Tips10Joerg Mertens
4 Aug 24    i i+* Re: Basic ps Tips7Rene Kita
4 Aug 24    i ii`* Re: Basic ps Tips6Joerg Mertens
5 Aug 24    i ii +* Re: Basic ps Tips4Lawrence D'Oliveiro
5 Aug 24    i ii i+* Re: Basic ps Tips2Joerg Mertens
5 Aug 24    i ii ii`- The whole point of the BSDs is to be retro (Was: Basic ps Tips)1Kenny McCormack
5 Aug 24    i ii i`- Re: Basic ps Tips1Christian Weisgerber
5 Aug 24    i ii `- Re: Basic ps Tips1Rene Kita
4 Aug 24    i i`* Re: Basic ps Tips2Christian Weisgerber
5 Aug 24    i i `- Re: Basic ps Tips1Rene Kita
3 Aug 24    i `* Re: Basic ps Tips2Lawrence D'Oliveiro
4 Aug 24    i  `- Re: Basic ps Tips1John D Groenveld
4 Aug 24    `* Re: Basic ps Tips3Christian Weisgerber
4 Aug 24     `* Re: Basic ps Tips2Christian Weisgerber
5 Aug 24      `- Re: Basic ps Tips1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal