BSD 4_4_Lite1 release
[unix-history] / usr / src / bin / ps / ps.c
index 700a84e..06d1d5f 100644 (file)
@@ -1,18 +1,44 @@
 /*-
 /*-
- * Copyright (c) 1990, 1993
+ * Copyright (c) 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  *     The Regents of the University of California.  All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
 static char copyright[] =
  */
 
 #ifndef lint
 static char copyright[] =
-"@(#) Copyright (c) 1990, 1993\n\
+"@(#) Copyright (c) 1990, 1993, 1994\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ps.c       8.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)ps.c       8.4 (Berkeley) 4/2/94";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -78,13 +104,14 @@ main(argc, argv)
        int argc;
        char *argv[];
 {
        int argc;
        char *argv[];
 {
-       register struct kinfo_proc *kp;
-       register struct varent *vent;
-       int nentries;
-       register int i;
+       struct kinfo_proc *kp;
+       struct varent *vent;
        struct winsize ws;
        dev_t ttydev;
        struct winsize ws;
        dev_t ttydev;
-       int all, ch, flag, fmt, lineno, pid, prtheader, uid, wflag, what, xflg;
+       pid_t pid;
+       uid_t uid;
+       int all, ch, flag, i, fmt, lineno, nentries;
+       int prtheader, wflag, what, xflg;
        char *nlistf, *memf, *swapf, errbuf[256];
 
        if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
        char *nlistf, *memf, *swapf, errbuf[256];
 
        if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
@@ -99,7 +126,8 @@ main(argc, argv)
                argv[1] = kludge_oldps_options(argv[1]);
 
        all = fmt = prtheader = wflag = xflg = 0;
                argv[1] = kludge_oldps_options(argv[1]);
 
        all = fmt = prtheader = wflag = xflg = 0;
-       pid = uid = -1;
+       pid = -1;
+       uid = (uid_t) -1;
        ttydev = NODEV;
        memf = nlistf = swapf = NULL;
        while ((ch = getopt(argc, argv,
        ttydev = NODEV;
        memf = nlistf = swapf = NULL;
        while ((ch = getopt(argc, argv,
@@ -153,7 +181,7 @@ main(argc, argv)
                        fmt = 1;
                        break;
                case 'p':
                        fmt = 1;
                        break;
                case 'p':
-                       pid = atoi(optarg);
+                       pid = atol(optarg);
                        xflg = 1;
                        break;
                case 'r':
                        xflg = 1;
                        break;
                case 'r':
@@ -252,7 +280,7 @@ main(argc, argv)
        /*
         * get proc list
         */
        /*
         * get proc list
         */
-       if (uid != -1) {
+       if (uid != (uid_t) -1) {
                what = KERN_PROC_UID;
                flag = uid;
        } else if (ttydev != NODEV) {
                what = KERN_PROC_UID;
                flag = uid;
        } else if (ttydev != NODEV) {
@@ -261,6 +289,10 @@ main(argc, argv)
        } else if (pid != -1) {
                what = KERN_PROC_PID;
                flag = pid;
        } else if (pid != -1) {
                what = KERN_PROC_PID;
                flag = pid;
+       } else {
+               what = KERN_PROC_ALL;
+               flag = 0;
+       }
        /*
         * select procs
         */
        /*
         * select procs
         */
@@ -308,9 +340,9 @@ main(argc, argv)
 static void
 scanvars()
 {
 static void
 scanvars()
 {
-       register struct varent *vent;
-       register VAR *v;
-       register int i;
+       struct varent *vent;
+       VAR *v;
+       int i;
 
        for (vent = vhead; vent; vent = vent->next) {
                v = vent->var;
 
        for (vent = vhead; vent; vent = vent->next) {
                v = vent->var;
@@ -333,7 +365,7 @@ fmt(fn, ki, comm, maxlen)
        char *comm;
        int maxlen;
 {
        char *comm;
        int maxlen;
 {
-       register char *s;
+       char *s;
 
        if ((s =
            fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen)) == NULL)
 
        if ((s =
            fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen)) == NULL)
@@ -345,12 +377,12 @@ static void
 saveuser(ki)
        KINFO *ki;
 {
 saveuser(ki)
        KINFO *ki;
 {
-       register struct usave *usp = &ki->ki_u;
        struct pstats pstats;
        struct pstats pstats;
-       extern char *fmt_argv();
+       struct usave *usp;
 
 
+       usp = &ki->ki_u;
        if (kvm_read(kd, (u_long)&KI_PROC(ki)->p_addr->u_stats,
        if (kvm_read(kd, (u_long)&KI_PROC(ki)->p_addr->u_stats,
-                    (char *)&pstats, sizeof(pstats)) == sizeof(pstats)) {
+           (char *)&pstats, sizeof(pstats)) == sizeof(pstats)) {
                /*
                 * The u-area might be swapped out, and we can't get
                 * at it because we have a crashdump and no swap.
                /*
                 * The u-area might be swapped out, and we can't get
                 * at it because we have a crashdump and no swap.
@@ -462,7 +494,11 @@ kludge_oldps_options(s)
 static void
 usage()
 {
 static void
 usage()
 {
+
        (void)fprintf(stderr,
        (void)fprintf(stderr,
-"usage: ps [-aChjlmrSTuvwx] [-O|o fmt] [-p pid] [-t tty]\n\t  [-M core] [-N system] [-W swap]\n       ps [-L]\n");
+           "usage:\t%s\n\t   %s\n\t%s\n",
+           "ps [-aChjlmrSTuvwx] [-O|o fmt] [-p pid] [-t tty]",
+           "[-M core] [-N system] [-W swap]",
+           "ps [-L]");
        exit(1);
 }
        exit(1);
 }