Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*


  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * Portions Copyright 2009 Chad Mynhier
  27  */
  28 
  29 #include <sys/types.h>
  30 #include <sys/resource.h>
  31 #include <sys/loadavg.h>
  32 #include <sys/time.h>
  33 #include <sys/pset.h>
  34 #include <sys/vm_usage.h>
  35 #include <zone.h>
  36 #include <libzonecfg.h>
  37 
  38 #include <stdio.h>
  39 #include <stdlib.h>
  40 #include <unistd.h>
  41 #include <dirent.h>
  42 #include <string.h>


  58 #include "prtable.h"
  59 #include "prsort.h"
  60 #include "prfile.h"
  61 
  62 /*
  63  * x86 <sys/regs.h> ERR conflicts with <curses.h> ERR.  For the purposes
  64  * of this file, we care about the curses.h ERR so include that last.
  65  */
  66 
  67 #if     defined(ERR)
  68 #undef  ERR
  69 #endif
  70 
  71 #ifndef TEXT_DOMAIN                     /* should be defined by cc -D */
  72 #define TEXT_DOMAIN     "SYS_TEST"      /* use this only if it wasn't */
  73 #endif
  74 
  75 #include <curses.h>
  76 #include <term.h>
  77 




  78 #define PSINFO_HEADER_PROC \
  79 "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP       "
  80 #define PSINFO_HEADER_PROC_LGRP \
  81 "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/NLWP  "
  82 #define PSINFO_HEADER_LWP \
  83 "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/LWPID      "
  84 #define PSINFO_HEADER_LWP_LGRP \
  85 "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/LWPID "
  86 #define USAGE_HEADER_PROC \
  87 "   PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/NLWP  "
  88 #define USAGE_HEADER_LWP \
  89 "   PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/LWPID "
  90 #define USER_HEADER_PROC \
  91 " NPROC USERNAME  SWAP   RSS MEMORY      TIME  CPU                             "
  92 #define USER_HEADER_LWP \
  93 "  NLWP USERNAME  SWAP   RSS MEMORY      TIME  CPU                             "
  94 #define TASK_HEADER_PROC \
  95 "TASKID    NPROC  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
  96 #define TASK_HEADER_LWP \
  97 "TASKID     NLWP  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
  98 #define PROJECT_HEADER_PROC \
  99 "PROJID    NPROC  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 100 #define PROJECT_HEADER_LWP \
 101 "PROJID     NLWP  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 102 #define ZONE_HEADER_PROC \
 103 "ZONEID    NPROC  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 104 #define ZONE_HEADER_LWP \
 105 "ZONEID     NLWP  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 106 #define PSINFO_LINE \
 107 "%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %-.16s/%d"
 108 #define PSINFO_LINE_LGRP \
 109 "%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %4d %-.16s/%d"
 110 #define USAGE_LINE \
 111 "%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\
 112 "%3.3s %-.12s/%d"
 113 #define USER_LINE \
 114 "%6d %-8s %5.5s %5.5s   %3.3s%% %9s %3.3s%%"
 115 #define TASK_LINE \
 116 "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 117 #define PROJECT_LINE \
 118 "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 119 #define ZONE_LINE \
 120 "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 121 
 122 #define TOTAL_LINE \
 123 "Total: %d processes, %d lwps, load averages: %3.2f, %3.2f, %3.2f"
 124 
 125 /* global variables */
 126 
 127 static char     *t_ulon;                        /* termcap: start underline */
 128 static char     *t_uloff;                       /* termcap: end underline */
 129 static char     *t_up;                          /* termcap: cursor 1 line up */
 130 static char     *t_eol;                         /* termcap: clear end of line */
 131 static char     *t_smcup;                       /* termcap: cursor mvcap on */
 132 static char     *t_rmcup;                       /* termcap: cursor mvcap off */


 429         (void) putchar('\n');
 430 
 431         for (i = 0; i < list->l_used; i++) {
 432                 switch (list->l_type) {
 433                 case LT_PROJECTS:
 434                 case LT_TASKS:
 435                 case LT_USERS:
 436                 case LT_ZONES:
 437                         id = list->l_ptrs[i];
 438                         /*
 439                          * CPU usage and memory usage normalization
 440                          */
 441                         if (total_cpu >= 100)
 442                                 cpu = (100 * id->id_pctcpu) / total_cpu;
 443                         else
 444                                 cpu = id->id_pctcpu;
 445                         if (id->id_sizematch == B_FALSE && total_mem >= 100)
 446                                 mem = (100 * id->id_pctmem) / total_mem;
 447                         else
 448                                 mem = id->id_pctmem;
 449                         if (list->l_type == LT_USERS)
 450                                 pwd_getname(id->id_uid, pname, LOGNAME_MAX + 1,
 451                                     opts.o_outpmode & OPT_NORESOLVE);
 452                         else if (list->l_type == LT_ZONES)


 453                                 getzonename(id->id_zoneid, zonename,
 454                                     ZONENAME_MAX);
 455                         else


 456                                 getprojname(id->id_projid, projname,
 457                                     PROJNAME_MAX,
 458                                     opts.o_outpmode & OPT_NORESOLVE);



 459                         Format_size(psize, id->id_size, 6);
 460                         Format_size(prssize, id->id_rssize, 6);
 461                         Format_pct(pmem, mem, 4);
 462                         Format_pct(pcpu, cpu, 4);
 463                         Format_time(ptime, id->id_time, 10);
 464                         if (opts.o_outpmode & OPT_TTY)
 465                                 (void) putchar('\r');
 466                         if (list->l_type == LT_PROJECTS)
 467                                 (void) printf(PROJECT_LINE, (int)id->id_projid,
 468                                     id->id_nproc, psize, prssize, pmem, ptime,
 469                                     pcpu, projname);
 470                         else if (list->l_type == LT_TASKS)
 471                                 (void) printf(TASK_LINE, (int)id->id_taskid,
 472                                     id->id_nproc, psize, prssize, pmem, ptime,
 473                                     pcpu, projname);
 474                         else if (list->l_type == LT_ZONES)
 475                                 (void) printf(ZONE_LINE, (int)id->id_zoneid,
 476                                     id->id_nproc, psize, prssize, pmem, ptime,
 477                                     pcpu, zonename);
 478                         else
 479                                 (void) printf(USER_LINE, id->id_nproc, pname,
 480                                     psize, prssize, pmem, ptime, pcpu);
 481                         (void) putp(t_eol);
 482                         (void) putchar('\n');
 483                         break;
 484                 case LT_LWPS:
 485                         lwp = list->l_ptrs[i];
 486                         if (opts.o_outpmode & OPT_LWPS)
 487                                 lwpid = lwp->li_info.pr_lwp.pr_lwpid;
 488                         else
 489                                 lwpid = lwp->li_info.pr_nlwp +
 490                                     lwp->li_info.pr_nzomb;
 491                         pwd_getname(lwp->li_info.pr_uid, pname, LOGNAME_MAX + 1,
 492                             opts.o_outpmode & OPT_NORESOLVE);


 493                         if (opts.o_outpmode & OPT_PSINFO) {
 494                                 Format_size(psize, lwp->li_info.pr_size, 6);
 495                                 Format_size(prssize, lwp->li_info.pr_rssize, 6);
 496                                 Format_state(pstate,
 497                                     lwp->li_info.pr_lwp.pr_sname,
 498                                     lwp->li_info.pr_lwp.pr_onpro, 7);
 499                                 if (strcmp(lwp->li_info.pr_lwp.pr_clname,
 500                                     "RT") == 0 ||
 501                                     strcmp(lwp->li_info.pr_lwp.pr_clname,
 502                                     "SYS") == 0 ||
 503                                     lwp->li_info.pr_lwp.pr_sname == 'Z')
 504                                         (void) strcpy(pnice, "  -");
 505                                 else
 506                                         Format_num(pnice,
 507                                             lwp->li_info.pr_lwp.pr_nice - NZERO,
 508                                             4);
 509                                 Format_num(ppri, lwp->li_info.pr_lwp.pr_pri, 4);
 510                                 Format_pct(pcpu,
 511                                     FRC2PCT(lwp->li_info.pr_lwp.pr_pctcpu), 4);
 512                                 if (opts.o_outpmode & OPT_LWPS)
 513                                         Format_time(ptime,
 514                                             lwp->li_info.pr_lwp.pr_time.tv_sec,
 515                                             10);
 516                                 else
 517                                         Format_time(ptime,
 518                                             lwp->li_info.pr_time.tv_sec, 10);
 519                                 if (opts.o_outpmode & OPT_TTY)
 520                                         (void) putchar('\r');
 521                                 stripfname(lwp->li_info.pr_fname);
 522                                 if (opts.o_outpmode & OPT_LGRP) {
 523                                         (void) printf(PSINFO_LINE_LGRP,
 524                                             (int)lwp->li_info.pr_pid, pname,
 525                                             psize, prssize, pstate, ppri, pnice,
 526                                             ptime, pcpu,
 527                                             (int)lwp->li_info.pr_lwp.pr_lgrp,
 528                                             lwp->li_info.pr_fname, lwpid);
 529                                 } else {
 530                                         (void) printf(PSINFO_LINE,
 531                                             (int)lwp->li_info.pr_pid, pname,
 532                                             psize, prssize, pstate, ppri, pnice,

 533                                             ptime, pcpu,
 534                                             lwp->li_info.pr_fname, lwpid);
 535                                 }
 536                                 (void) putp(t_eol);
 537                                 (void) putchar('\n');
 538                         }
 539                         if (opts.o_outpmode & OPT_MSACCT) {
 540                                 Format_pct(usr, lwp->li_usr, 4);
 541                                 Format_pct(sys, lwp->li_sys, 4);
 542                                 Format_pct(slp, lwp->li_slp, 4);
 543                                 Format_num(vcx, lwp->li_vcx, 4);
 544                                 Format_num(icx, lwp->li_icx, 4);
 545                                 Format_num(scl, lwp->li_scl, 4);
 546                                 Format_num(sig, lwp->li_sig, 4);
 547                                 Format_pct(trp, lwp->li_trp, 4);
 548                                 Format_pct(tfl, lwp->li_tfl, 4);
 549                                 Format_pct(dfl, lwp->li_dfl, 4);
 550                                 Format_pct(lck, lwp->li_lck, 4);
 551                                 Format_pct(lat, lwp->li_lat, 4);
 552                                 if (opts.o_outpmode & OPT_TTY)


1347 int
1348 main(int argc, char **argv)
1349 {
1350         DIR *procdir;
1351         char *p;
1352         char *sortk = "cpu";    /* default sort key */
1353         int opt;
1354         int timeout;
1355         struct pollfd pollset;
1356         char key;
1357 
1358         (void) setlocale(LC_ALL, "");
1359         (void) textdomain(TEXT_DOMAIN);
1360         Progname(argv[0]);
1361         lwpid_init();
1362         fd_init(Setrlimit());
1363 
1364         pagesize = sysconf(_SC_PAGESIZE);
1365 
1366         while ((opt = getopt(argc, argv,
1367             "vcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJz:Z")) != (int)EOF) {
1368                 switch (opt) {
1369                 case 'r':
1370                         opts.o_outpmode |= OPT_NORESOLVE;
1371                         break;
1372                 case 'R':
1373                         opts.o_outpmode |= OPT_REALTIME;
1374                         break;
1375                 case 'c':
1376                         opts.o_outpmode &= ~OPT_TERMCAP;
1377                         opts.o_outpmode &= ~OPT_FULLSCREEN;
1378                         break;
1379                 case 'd':
1380                         if (optarg) {
1381                                 if (*optarg == 'u')
1382                                         opts.o_outpmode |= OPT_UDATE;
1383                                 else if (*optarg == 'd')
1384                                         opts.o_outpmode |= OPT_DDATE;
1385                                 else
1386                                         Usage();
1387                         } else {


1444                         break;
1445                 case 'p':
1446                         fill_table(&pid_tbl, optarg, 'p');
1447                         break;
1448                 case 'C':
1449                         fill_set_table(optarg);
1450                         opts.o_outpmode |= OPT_PSETS;
1451                         break;
1452                 case 'P':
1453                         fill_table(&cpu_tbl, optarg, 'P');
1454                         break;
1455                 case 'k':
1456                         fill_table(&tsk_tbl, optarg, 'k');
1457                         break;
1458                 case 'j':
1459                         fill_prj_table(optarg);
1460                         break;
1461                 case 'L':
1462                         opts.o_outpmode |= OPT_LWPS;
1463                         break;



1464                 case 'z':
1465                         if ((p = strtok(optarg, ", ")) == NULL)
1466                                 Die(gettext("invalid argument for -z\n"));
1467                         add_zone(&zone_tbl, p);
1468                         while (p = strtok(NULL, ", "))
1469                                 add_zone(&zone_tbl, p);
1470                         break;
1471                 case 'Z':
1472                         opts.o_outpmode |= OPT_SPLIT | OPT_ZONES;
1473                         break;
1474                 default:
1475                         Usage();
1476                 }
1477         }
1478 
1479         (void) atexit(Exit);
1480         if ((opts.o_outpmode & OPT_USERS) &&
1481             !(opts.o_outpmode & OPT_SPLIT))
1482                 opts.o_nbottom = opts.o_ntop;
1483         if (opts.o_ntop == 0 || opts.o_nbottom == 0)




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2013 Gary Mills
  24  *
  25  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  *
  28  * Portions Copyright 2009 Chad Mynhier
  29  */
  30 
  31 #include <sys/types.h>
  32 #include <sys/resource.h>
  33 #include <sys/loadavg.h>
  34 #include <sys/time.h>
  35 #include <sys/pset.h>
  36 #include <sys/vm_usage.h>
  37 #include <zone.h>
  38 #include <libzonecfg.h>
  39 
  40 #include <stdio.h>
  41 #include <stdlib.h>
  42 #include <unistd.h>
  43 #include <dirent.h>
  44 #include <string.h>


  60 #include "prtable.h"
  61 #include "prsort.h"
  62 #include "prfile.h"
  63 
  64 /*
  65  * x86 <sys/regs.h> ERR conflicts with <curses.h> ERR.  For the purposes
  66  * of this file, we care about the curses.h ERR so include that last.
  67  */
  68 
  69 #if     defined(ERR)
  70 #undef  ERR
  71 #endif
  72 
  73 #ifndef TEXT_DOMAIN                     /* should be defined by cc -D */
  74 #define TEXT_DOMAIN     "SYS_TEST"      /* use this only if it wasn't */
  75 #endif
  76 
  77 #include <curses.h>
  78 #include <term.h>
  79 
  80 #define LOGIN_WIDTH     8
  81 #define ZONE_WIDTH      28
  82 #define PROJECT_WIDTH   28
  83 
  84 #define PSINFO_HEADER_PROC \
  85 "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP       "
  86 #define PSINFO_HEADER_PROC_LGRP \
  87 "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/NLWP  "
  88 #define PSINFO_HEADER_LWP \
  89 "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/LWPID      "
  90 #define PSINFO_HEADER_LWP_LGRP \
  91 "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/LWPID "
  92 #define USAGE_HEADER_PROC \
  93 "   PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/NLWP  "
  94 #define USAGE_HEADER_LWP \
  95 "   PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/LWPID "
  96 #define USER_HEADER_PROC \
  97 " NPROC USERNAME  SWAP   RSS MEMORY      TIME  CPU                             "
  98 #define USER_HEADER_LWP \
  99 "  NLWP USERNAME  SWAP   RSS MEMORY      TIME  CPU                             "
 100 #define TASK_HEADER_PROC \
 101 "TASKID    NPROC  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 102 #define TASK_HEADER_LWP \
 103 "TASKID     NLWP  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 104 #define PROJECT_HEADER_PROC \
 105 "PROJID    NPROC  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 106 #define PROJECT_HEADER_LWP \
 107 "PROJID     NLWP  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 108 #define ZONE_HEADER_PROC \
 109 "ZONEID    NPROC  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 110 #define ZONE_HEADER_LWP \
 111 "ZONEID     NLWP  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 112 #define PSINFO_LINE \
 113 "%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %-.16s/%d"
 114 #define PSINFO_LINE_LGRP \
 115 "%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %4d %-.16s/%d"
 116 #define USAGE_LINE \
 117 "%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\
 118 "%3.3s %3.3s %-.12s/%d"
 119 #define USER_LINE \
 120 "%6d %-8s %5.5s %5.5s   %3.3s%% %9s %3.3s%%"
 121 #define TASK_LINE \
 122 "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 123 #define PROJECT_LINE \
 124 "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 125 #define ZONE_LINE \
 126 "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 127 
 128 #define TOTAL_LINE \
 129 "Total: %d processes, %d lwps, load averages: %3.2f, %3.2f, %3.2f"
 130 
 131 /* global variables */
 132 
 133 static char     *t_ulon;                        /* termcap: start underline */
 134 static char     *t_uloff;                       /* termcap: end underline */
 135 static char     *t_up;                          /* termcap: cursor 1 line up */
 136 static char     *t_eol;                         /* termcap: clear end of line */
 137 static char     *t_smcup;                       /* termcap: cursor mvcap on */
 138 static char     *t_rmcup;                       /* termcap: cursor mvcap off */


 435         (void) putchar('\n');
 436 
 437         for (i = 0; i < list->l_used; i++) {
 438                 switch (list->l_type) {
 439                 case LT_PROJECTS:
 440                 case LT_TASKS:
 441                 case LT_USERS:
 442                 case LT_ZONES:
 443                         id = list->l_ptrs[i];
 444                         /*
 445                          * CPU usage and memory usage normalization
 446                          */
 447                         if (total_cpu >= 100)
 448                                 cpu = (100 * id->id_pctcpu) / total_cpu;
 449                         else
 450                                 cpu = id->id_pctcpu;
 451                         if (id->id_sizematch == B_FALSE && total_mem >= 100)
 452                                 mem = (100 * id->id_pctmem) / total_mem;
 453                         else
 454                                 mem = id->id_pctmem;
 455                         if (list->l_type == LT_USERS) {
 456                                 pwd_getname(id->id_uid, pname, sizeof (pname),
 457                                     opts.o_outpmode & OPT_NORESOLVE,
 458                                     opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
 459                                     LOGIN_WIDTH);
 460                         } else if (list->l_type == LT_ZONES) {
 461                                 getzonename(id->id_zoneid, zonename,
 462                                     sizeof (zonename),
 463                                     opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
 464                                     ZONE_WIDTH);
 465                         } else {
 466                                 getprojname(id->id_projid, projname,
 467                                     sizeof (projname),
 468                                     opts.o_outpmode & OPT_NORESOLVE,
 469                                     opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
 470                                     PROJECT_WIDTH);
 471                         }
 472                         Format_size(psize, id->id_size, 6);
 473                         Format_size(prssize, id->id_rssize, 6);
 474                         Format_pct(pmem, mem, 4);
 475                         Format_pct(pcpu, cpu, 4);
 476                         Format_time(ptime, id->id_time, 10);
 477                         if (opts.o_outpmode & OPT_TTY)
 478                                 (void) putchar('\r');
 479                         if (list->l_type == LT_PROJECTS)
 480                                 (void) printf(PROJECT_LINE, (int)id->id_projid,
 481                                     id->id_nproc, psize, prssize, pmem, ptime,
 482                                     pcpu, projname);
 483                         else if (list->l_type == LT_TASKS)
 484                                 (void) printf(TASK_LINE, (int)id->id_taskid,
 485                                     id->id_nproc, psize, prssize, pmem, ptime,
 486                                     pcpu, projname);
 487                         else if (list->l_type == LT_ZONES)
 488                                 (void) printf(ZONE_LINE, (int)id->id_zoneid,
 489                                     id->id_nproc, psize, prssize, pmem, ptime,
 490                                     pcpu, zonename);
 491                         else
 492                                 (void) printf(USER_LINE, id->id_nproc, pname,
 493                                     psize, prssize, pmem, ptime, pcpu);
 494                         (void) putp(t_eol);
 495                         (void) putchar('\n');
 496                         break;
 497                 case LT_LWPS:
 498                         lwp = list->l_ptrs[i];
 499                         if (opts.o_outpmode & OPT_LWPS)
 500                                 lwpid = lwp->li_info.pr_lwp.pr_lwpid;
 501                         else
 502                                 lwpid = lwp->li_info.pr_nlwp +
 503                                     lwp->li_info.pr_nzomb;
 504                         pwd_getname(lwp->li_info.pr_uid, pname, sizeof (pname),
 505                             opts.o_outpmode & OPT_NORESOLVE,
 506                             opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
 507                             LOGIN_WIDTH);
 508                         if (opts.o_outpmode & OPT_PSINFO) {
 509                                 Format_size(psize, lwp->li_info.pr_size, 6);
 510                                 Format_size(prssize, lwp->li_info.pr_rssize, 6);
 511                                 Format_state(pstate,
 512                                     lwp->li_info.pr_lwp.pr_sname,
 513                                     lwp->li_info.pr_lwp.pr_onpro, 7);
 514                                 if (strcmp(lwp->li_info.pr_lwp.pr_clname,
 515                                     "RT") == 0 ||
 516                                     strcmp(lwp->li_info.pr_lwp.pr_clname,
 517                                     "SYS") == 0 ||
 518                                     lwp->li_info.pr_lwp.pr_sname == 'Z')
 519                                         (void) strcpy(pnice, "  -");
 520                                 else
 521                                         Format_num(pnice,
 522                                             lwp->li_info.pr_lwp.pr_nice - NZERO,
 523                                             4);
 524                                 Format_num(ppri, lwp->li_info.pr_lwp.pr_pri, 4);
 525                                 Format_pct(pcpu,
 526                                     FRC2PCT(lwp->li_info.pr_lwp.pr_pctcpu), 4);
 527                                 if (opts.o_outpmode & OPT_LWPS)
 528                                         Format_time(ptime,
 529                                             lwp->li_info.pr_lwp.pr_time.tv_sec,
 530                                             10);
 531                                 else
 532                                         Format_time(ptime,
 533                                             lwp->li_info.pr_time.tv_sec, 10);
 534                                 if (opts.o_outpmode & OPT_TTY)
 535                                         (void) putchar('\r');
 536                                 stripfname(lwp->li_info.pr_fname);
 537                                 if (opts.o_outpmode & OPT_LGRP) {
 538                                         (void) printf(PSINFO_LINE_LGRP,
 539                                             (int)lwp->li_info.pr_pid, pname,
 540                                             psize, prssize, pstate,
 541                                             ppri, pnice, ptime, pcpu,
 542                                             (int)lwp->li_info.pr_lwp.pr_lgrp,
 543                                             lwp->li_info.pr_fname, lwpid);
 544                                 } else {
 545                                         (void) printf(PSINFO_LINE,
 546                                             (int)lwp->li_info.pr_pid, pname,
 547                                             psize, prssize,
 548                                             pstate, ppri, pnice,
 549                                             ptime, pcpu,
 550                                             lwp->li_info.pr_fname, lwpid);
 551                                 }
 552                                 (void) putp(t_eol);
 553                                 (void) putchar('\n');
 554                         }
 555                         if (opts.o_outpmode & OPT_MSACCT) {
 556                                 Format_pct(usr, lwp->li_usr, 4);
 557                                 Format_pct(sys, lwp->li_sys, 4);
 558                                 Format_pct(slp, lwp->li_slp, 4);
 559                                 Format_num(vcx, lwp->li_vcx, 4);
 560                                 Format_num(icx, lwp->li_icx, 4);
 561                                 Format_num(scl, lwp->li_scl, 4);
 562                                 Format_num(sig, lwp->li_sig, 4);
 563                                 Format_pct(trp, lwp->li_trp, 4);
 564                                 Format_pct(tfl, lwp->li_tfl, 4);
 565                                 Format_pct(dfl, lwp->li_dfl, 4);
 566                                 Format_pct(lck, lwp->li_lck, 4);
 567                                 Format_pct(lat, lwp->li_lat, 4);
 568                                 if (opts.o_outpmode & OPT_TTY)


1363 int
1364 main(int argc, char **argv)
1365 {
1366         DIR *procdir;
1367         char *p;
1368         char *sortk = "cpu";    /* default sort key */
1369         int opt;
1370         int timeout;
1371         struct pollfd pollset;
1372         char key;
1373 
1374         (void) setlocale(LC_ALL, "");
1375         (void) textdomain(TEXT_DOMAIN);
1376         Progname(argv[0]);
1377         lwpid_init();
1378         fd_init(Setrlimit());
1379 
1380         pagesize = sysconf(_SC_PAGESIZE);
1381 
1382         while ((opt = getopt(argc, argv,
1383             "vcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJWz:Z")) != (int)EOF) {
1384                 switch (opt) {
1385                 case 'r':
1386                         opts.o_outpmode |= OPT_NORESOLVE;
1387                         break;
1388                 case 'R':
1389                         opts.o_outpmode |= OPT_REALTIME;
1390                         break;
1391                 case 'c':
1392                         opts.o_outpmode &= ~OPT_TERMCAP;
1393                         opts.o_outpmode &= ~OPT_FULLSCREEN;
1394                         break;
1395                 case 'd':
1396                         if (optarg) {
1397                                 if (*optarg == 'u')
1398                                         opts.o_outpmode |= OPT_UDATE;
1399                                 else if (*optarg == 'd')
1400                                         opts.o_outpmode |= OPT_DDATE;
1401                                 else
1402                                         Usage();
1403                         } else {


1460                         break;
1461                 case 'p':
1462                         fill_table(&pid_tbl, optarg, 'p');
1463                         break;
1464                 case 'C':
1465                         fill_set_table(optarg);
1466                         opts.o_outpmode |= OPT_PSETS;
1467                         break;
1468                 case 'P':
1469                         fill_table(&cpu_tbl, optarg, 'P');
1470                         break;
1471                 case 'k':
1472                         fill_table(&tsk_tbl, optarg, 'k');
1473                         break;
1474                 case 'j':
1475                         fill_prj_table(optarg);
1476                         break;
1477                 case 'L':
1478                         opts.o_outpmode |= OPT_LWPS;
1479                         break;
1480                 case 'W':
1481                         opts.o_outpmode |= OPT_TRUNC;
1482                         break;
1483                 case 'z':
1484                         if ((p = strtok(optarg, ", ")) == NULL)
1485                                 Die(gettext("invalid argument for -z\n"));
1486                         add_zone(&zone_tbl, p);
1487                         while (p = strtok(NULL, ", "))
1488                                 add_zone(&zone_tbl, p);
1489                         break;
1490                 case 'Z':
1491                         opts.o_outpmode |= OPT_SPLIT | OPT_ZONES;
1492                         break;
1493                 default:
1494                         Usage();
1495                 }
1496         }
1497 
1498         (void) atexit(Exit);
1499         if ((opts.o_outpmode & OPT_USERS) &&
1500             !(opts.o_outpmode & OPT_SPLIT))
1501                 opts.o_nbottom = opts.o_ntop;
1502         if (opts.o_ntop == 0 || opts.o_nbottom == 0)