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>
  43 #include <errno.h>
  44 #include <poll.h>
  45 #include <ctype.h>
  46 #include <fcntl.h>
  47 #include <limits.h>
  48 #include <signal.h>
  49 #include <time.h>
  50 #include <project.h>
  51 
  52 #include <langinfo.h>
  53 #include <libintl.h>
  54 #include <locale.h>
  55 
  56 #include "prstat.h"
  57 #include "prutil.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 */


 337                  * If no match is found, prstat will use the size already
 338                  * gathered from psinfo.
 339                  */
 340         }
 341         free(results);
 342 }
 343 
 344 /*
 345  * A routine to display the contents of the list on the screen
 346  */
 347 static void
 348 list_print(list_t *list)
 349 {
 350         lwp_info_t *lwp;
 351         id_info_t *id;
 352         char usr[4], sys[4], trp[4], tfl[4];
 353         char dfl[4], lck[4], slp[4], lat[4];
 354         char vcx[4], icx[4], scl[4], sig[4];
 355         char psize[6], prssize[6], pmem[6], pcpu[6], ptime[12];
 356         char pstate[7], pnice[4], ppri[4];
 357         char pname[LOGNAME_MAX+1];
 358         char projname[PROJNAME_MAX+1];
 359         char zonename[ZONENAME_MAX+1];
 360         float cpu, mem;
 361         double loadavg[3] = {0, 0, 0};
 362         int i, lwpid;
 363 
 364         if (foreach_element(&set_tbl, &loadavg, psetloadavg) == 0) {
 365                 /*
 366                  * If processor sets aren't specified, we display system-wide
 367                  * load averages.
 368                  */
 369                 (void) getloadavg(loadavg, 3);
 370         }
 371 
 372         if (((opts.o_outpmode & OPT_UDATE) || (opts.o_outpmode & OPT_DDATE)) &&
 373             ((list->l_type == LT_LWPS) || !(opts.o_outpmode & OPT_SPLIT)))
 374                 print_timestamp();
 375         if (opts.o_outpmode & OPT_TTY)
 376                 (void) putchar('\r');
 377         (void) putp(t_ulon);


 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)




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


 349                  * If no match is found, prstat will use the size already
 350                  * gathered from psinfo.
 351                  */
 352         }
 353         free(results);
 354 }
 355 
 356 /*
 357  * A routine to display the contents of the list on the screen
 358  */
 359 static void
 360 list_print(list_t *list)
 361 {
 362         lwp_info_t *lwp;
 363         id_info_t *id;
 364         char usr[4], sys[4], trp[4], tfl[4];
 365         char dfl[4], lck[4], slp[4], lat[4];
 366         char vcx[4], icx[4], scl[4], sig[4];
 367         char psize[6], prssize[6], pmem[6], pcpu[6], ptime[12];
 368         char pstate[7], pnice[4], ppri[4];
 369         char pname[_LOGNAME_MAX+1];
 370         char projname[PROJNAME_MAX+1];
 371         char zonename[ZONENAME_MAX+1];
 372         float cpu, mem;
 373         double loadavg[3] = {0, 0, 0};
 374         int i, lwpid;
 375 
 376         if (foreach_element(&set_tbl, &loadavg, psetloadavg) == 0) {
 377                 /*
 378                  * If processor sets aren't specified, we display system-wide
 379                  * load averages.
 380                  */
 381                 (void) getloadavg(loadavg, 3);
 382         }
 383 
 384         if (((opts.o_outpmode & OPT_UDATE) || (opts.o_outpmode & OPT_DDATE)) &&
 385             ((list->l_type == LT_LWPS) || !(opts.o_outpmode & OPT_SPLIT)))
 386                 print_timestamp();
 387         if (opts.o_outpmode & OPT_TTY)
 388                 (void) putchar('\r');
 389         (void) putp(t_ulon);


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