>On second thought it seems the ps command is switchning between bsd behaviour 
>(old /usr/ucb/ps) if
 options are not preceded with '-' and "new" solaris behaviour if there is a '-'
>Is that correct ?

Almost.

This is what the main routine in ps look like today:

int
main(int argc, char **argv)
{
        const char *me;

        /*
         * The original two ps'es are linked in a single binary;
         * their main()s are renamed to stdmain for /usr/bin/ps and
         * ucbmain for /usr/ucb/ps.
         * We try to figure out which instance of ps the user wants to run.
         * Traditionally, the UCB variant doesn't require the flag argument
         * start with a "-".  If the first argument doesn't start with a
         * "-", we call "ucbmain".
         * If there's a first argument and it starts with a "-", we check
         * whether any of the options isn't acceptable to "ucbmain"; in that
         * case we run "stdmain".
         * If we can't tell from the options which main to call, we check
         * the binary we are running.  We default to "stdmain" but
         * any mention in the executable name of "ucb" causes us to call
         * ucbmain.
         */
        if (argv[1] != NULL) {
                if (argv[1][0] != '-')
                        return (ucbmain(argc, argv));
                else if (argv[1][strspn(argv[1], UCB_OPTS)] != '\0')
                        return (stdmain(argc, argv));
        }

        me = getexecname();

        if (me != NULL && strstr(me, "ucb") != NULL)
                return (ucbmain(argc, argv));
        else
                return (stdmain(argc, argv));
}

E.g.:

% ps -uxg
ps: unknown user xg
% /usr/ucb/ps -uxg
USER       PID %CPU %MEM   SZ  RSS TT       S    START  TIME COMMAND
...

% ps -a (bin in PATH before ucb)
  PID TTY         TIME CMD
 6791 pts/5       0:00 tcsh
 7185 pts/4       0:00 less
 7190 pts/5       0:00 ps
% ps -a (ucb before bin)
   PID TT       S  TIME COMMAND
  3933 console  S  0:00 /usr/lib/saf/ttymon -g -d /dev/console -l console -T xt
  6730 pts/1    S  0:00 tcsh
  6710 pts/2    S  0:00 tcsh
  6687 pts/3    S  0:00 tcsh
  6711 pts/4    S  0:00 tcsh
  7185 pts/4    S  0:00 /opt/bin/less usr/src/cmd/ps/ps.c
  6686 pts/5    S  0:00 tcsh
  6791 pts/5    T  0:00 /usr/bin/tcsh
  7192 pts/5    O  0:00 ps -a


Mostly it works nice except, possibly, when you want to get the usage 
message.

Casper

_______________________________________________
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org

Reply via email to