home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xsw / pscpu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-09  |  23.6 KB  |  896 lines

  1. /*
  2.  *    @(#) pscpu.c 9.2 93/09/15 SCOINC
  3.  */
  4. /***************************************************************************
  5.  *
  6.  *    Copyright (c) 1990-1993        The Santa Cruz Operation, Inc.
  7.  *
  8.  *    All rights reserved.  No part of this program or publication may be
  9.  *    reproduced, transmitted, transcribed, stored in a retrieval system,
  10.  *    or translated into any language or computer language, in any form or
  11.  *    by any means, electronic, mechanical, magnetic, optical, chemical,
  12.  *    biological, or otherwise, without the prior written permission of:
  13.  *
  14.  *        The Santa Cruz Operation , Inc.        (408) 425-7222
  15.  *        400 Encinal St., Santa Cruz, California 95060 USA
  16.  *
  17.  **************************************************************************/
  18. /*
  19.  * Modification History
  20.  *
  21.  * S002, 15-Sep-93, rickra
  22.  *    Did lots of little bug fixes...
  23.  *
  24.  * S001, 27-May-93, rickra
  25.  *     Did alot of stuff.....
  26.  *    Added seperate window support.
  27.  *    Added pixmap support.....
  28.  *
  29.  * S000, 30-Sep-92, rickra
  30.  *     Added copyright and modification history
  31.  *    Change hard coded color referneces to user configurable.
  32.  */
  33. /*+-------------------------------------------------------------------------
  34.     pscpu.c - XSW proc status detail
  35.  
  36.   Defined functions:
  37.     display_proc_stat(x,y,iproc)
  38. --------------------------------------------------------------------------*/
  39.  
  40. #include <X11/Xlib.h>
  41. #include <X11/Xutil.h>
  42. #include <X11/Intrinsic.h>
  43. #include <X11/Shell.h>
  44. #include <X11/StringDefs.h>
  45. #include <Xm/Xm.h>
  46. #include <Xm/MainW.h>
  47. #include <Xm/DrawingA.h>
  48. #include <Xm/Label.h>
  49.  
  50. #include "include/unixincs.h"
  51. #include "include/resources.h"
  52. #include "include/xswboth.h"
  53. #include "include/buttons.h"
  54. #include "include/libkmem.h"
  55. #include "include/libmem.h"
  56. #include "include/libswap.h"
  57.  
  58. #include "include/xsw.h"
  59.  
  60. extern struct NetworkXswStruct *current_server;
  61.  
  62. extern struct my_user_struct user;
  63. extern struct my_user_struct old_user;
  64.  
  65. extern Pixmap   pixmap;
  66.  
  67.  
  68. long    total_ps_ticks = 0;
  69.  
  70. /*+-----------------------------------------------------------------------
  71.         char *get_cpu_time_str(ticks)
  72.   6-char static string address is returned
  73. ------------------------------------------------------------------------*/
  74. char           *
  75. get_cpu_time_str (ticks)
  76.      time_t          ticks;
  77. {
  78.   static char     timestr[10];
  79.   time_t          mm, ss;
  80.  
  81.   ticks /= current_server -> hz;
  82.   mm = ticks / 60L;
  83.   ticks -= mm * 60L;
  84.   ss = ticks;
  85.  
  86.   if (mm > 9999)
  87.     (void) strcpy (timestr, ">9999m");
  88.   else if (mm > 999)
  89.     (void) sprintf (timestr, "%5ldm", mm);
  90.   else
  91.     (void) sprintf (timestr, "%3lu:%02lu", mm, ss);
  92.  
  93.   return (timestr);
  94.  
  95. }                /* end of get_cpu_time_str */
  96.  
  97.  
  98. /*+-------------------------------------------------------------------------
  99.     ppproc_state_compare(ppp1,ppp2)
  100. --------------------------------------------------------------------------*/
  101. ppproc_state_compare (ppp1, ppp2)
  102.      struct my_proc_struct **ppp1;
  103.      struct my_proc_struct **ppp2;
  104. {
  105.  
  106.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  107.     return (0);
  108.   else if ((*ppp1) -> p_pid == 32767)
  109.     return (1);
  110.   else if ((*ppp2) -> p_pid == 32767)
  111.     return (-1);
  112.  
  113.   if (current_server -> ps_cpu_sort_order == 1)
  114.     return ((*ppp2) -> p_stat - (*ppp1) -> p_stat);
  115.   else
  116.     return ((*ppp1) -> p_stat - (*ppp2) -> p_stat);
  117.  
  118. }                /* end of ppproc_state_compare */
  119.  
  120.  
  121. /*+-------------------------------------------------------------------------
  122.     ppproc_user_compare(ppp1,ppp2)
  123. --------------------------------------------------------------------------*/
  124. ppproc_user_compare (ppp1, ppp2)
  125.      struct my_proc_struct **ppp1;
  126.      struct my_proc_struct **ppp2;
  127. {
  128.  
  129.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  130.     return (0);
  131.   else if ((*ppp1) -> p_pid == 32767)
  132.     return (1);
  133.   else if ((*ppp2) -> p_pid == 32767)
  134.     return (-1);
  135.  
  136.   if (current_server -> ps_cpu_sort_order == 1)
  137.     return (strcmp ((*ppp2) -> name, (*ppp1) -> name));
  138.   else
  139.     return (strcmp ((*ppp1) -> name, (*ppp2) -> name));
  140.  
  141. }                /* end of ppproc_user_compare */
  142.  
  143. /*+-------------------------------------------------------------------------
  144.     ppproc_pid_compare(ppp1,ppp2)
  145. --------------------------------------------------------------------------*/
  146. ppproc_pid_compare (ppp1, ppp2)
  147.      struct my_proc_struct **ppp1;
  148.      struct my_proc_struct **ppp2;
  149. {
  150.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  151.     return (0);
  152.   else if ((*ppp1) -> p_pid == 32767)
  153.     return (1);
  154.   else if ((*ppp2) -> p_pid == 32767)
  155.     return (-1);
  156.  
  157.   if (current_server -> ps_cpu_sort_order == 1)
  158.     return ((*ppp2) -> p_pid - (*ppp1) -> p_pid);
  159.   else
  160.     return ((*ppp1) -> p_pid - (*ppp2) -> p_pid);
  161. }                /* end of ppproc_pid_compare */
  162.  
  163. /*+-------------------------------------------------------------------------
  164.     ppproc_cpu_compare(ppp1,ppp2)
  165. --------------------------------------------------------------------------*/
  166. ppproc_cpu_compare (ppp1, ppp2)
  167.      struct my_proc_struct **ppp1;
  168.      struct my_proc_struct **ppp2;
  169. {
  170.  
  171.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  172.     return (0);
  173.   else if ((*ppp1) -> p_pid == 32767)
  174.     return (1);
  175.   else if ((*ppp2) -> p_pid == 32767)
  176.     return (-1);
  177.  
  178.   if (current_server -> ps_cpu_sort_order == 1)
  179.     return ((*ppp2) -> p_cpu - (*ppp1) -> p_cpu);
  180.   else
  181.     return ((*ppp1) -> p_cpu - (*ppp2) -> p_cpu);
  182.  
  183. }                /* end of ppproc_cpu_compare */
  184.  
  185. /*+-------------------------------------------------------------------------
  186.     ppproc_pri_compare(ppp1,ppp2)
  187. --------------------------------------------------------------------------*/
  188. ppproc_pri_compare (ppp1, ppp2)
  189.      struct my_proc_struct **ppp1;
  190.      struct my_proc_struct **ppp2;
  191. {
  192.  
  193.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  194.     return (0);
  195.   else if ((*ppp1) -> p_pid == 32767)
  196.     return (1);
  197.   else if ((*ppp2) -> p_pid == 32767)
  198.     return (-1);
  199.  
  200.   if (current_server -> ps_cpu_sort_order == 1)
  201.     return ((*ppp2) -> p_pri - (*ppp1) -> p_pri);
  202.   else
  203.     return ((*ppp1) -> p_pri - (*ppp2) -> p_pri);
  204.  
  205. }                /* end of ppproc_pri_compare */
  206.  
  207.  
  208. /*+-------------------------------------------------------------------------
  209.     ppproc_ni_compare(ppp1,ppp2)
  210. --------------------------------------------------------------------------*/
  211. ppproc_ni_compare (ppp1, ppp2)
  212.      struct my_proc_struct **ppp1;
  213.      struct my_proc_struct **ppp2;
  214. {
  215.  
  216.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  217.     return (0);
  218.   else if ((*ppp1) -> p_pid == 32767)
  219.     return (1);
  220.   else if ((*ppp2) -> p_pid == 32767)
  221.     return (-1);
  222.  
  223.  
  224.   if (current_server -> ps_cpu_sort_order == 1)
  225.     return ((*ppp2) -> p_nice - (*ppp1) -> p_nice);
  226.   else
  227.     return ((*ppp1) -> p_nice - (*ppp2) -> p_nice);
  228.  
  229. }                /* end of ppproc_ni_compare */
  230.  
  231. /*+-------------------------------------------------------------------------
  232.     ppproc_ucpu_compare(ppp1,ppp2)
  233. --------------------------------------------------------------------------*/
  234. ppproc_ucpu_compare (ppp1, ppp2)
  235.      struct my_proc_struct **ppp1;
  236.      struct my_proc_struct **ppp2;
  237. {
  238.   struct my_user_struct user1;
  239.   struct my_user_struct user2;
  240.   struct my_user_struct old_user1;
  241.   struct my_user_struct old_user2;
  242.   int             i, j, k, l;
  243.  
  244.   i = get_user (&(**ppp1), &user1);
  245.  
  246.   j = get_user (&(**ppp2), &user2);
  247.  
  248.   k = get_old_user (&(**ppp1), &old_user1);
  249.  
  250.   l = get_old_user (&(**ppp2), &old_user2);
  251.  
  252.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  253.     return (0);
  254.   else if (((*ppp1) -> p_pid == 32767) || (!i))
  255.     return (1);
  256.   else if (((*ppp2) -> p_pid == 32767) || (!j))
  257.     return (-1);
  258.  
  259.   if (current_server -> ps_cpu_sort_order == 1)
  260.     {
  261.       if (current_server -> ps_display_mode == 13)
  262.     return (user2.u_utime - user1.u_utime);
  263.       else
  264.     return ((user2.u_utime - old_user2.u_utime) -
  265.         (user1.u_utime - old_user1.u_utime));
  266.     }
  267.   else
  268.     {
  269.       if (current_server -> ps_display_mode == 13)
  270.     return (user1.u_utime - user2.u_utime);
  271.       else
  272.     return ((user1.u_utime - old_user1.u_utime) -
  273.         (user2.u_utime - old_user2.u_utime));
  274.  
  275.  
  276.     }
  277.  
  278.  
  279. }                /* end of ppproc_ucpu_compare */
  280.  
  281. /*+-------------------------------------------------------------------------
  282.     ppproc_ucpu_scpu_compare(ppp1,ppp2)
  283. --------------------------------------------------------------------------*/
  284. ppproc_ucpu_scpu_compare (ppp1, ppp2)
  285.      struct my_proc_struct **ppp1;
  286.      struct my_proc_struct **ppp2;
  287. {
  288.   struct my_user_struct user1;
  289.   struct my_user_struct user2;
  290.   struct my_user_struct old_user1;
  291.   struct my_user_struct old_user2;
  292.   int             i, j, k, l;
  293.   i = get_user (&(**ppp1), &user1);
  294.  
  295.   j = get_user (&(**ppp2), &user2);
  296.  
  297.   k = get_old_user (&(**ppp1), &old_user1);
  298.  
  299.   l = get_old_user (&(**ppp2), &old_user2);
  300.  
  301.  
  302.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  303.     return (0);
  304.   else if (((*ppp1) -> p_pid == 32767) || (!i))
  305.     return (1);
  306.   else if (((*ppp2) -> p_pid == 32767) || (!j))
  307.     return (-1);
  308.  
  309.  
  310.   if (current_server -> ps_cpu_sort_order == 1)
  311.     {
  312.       if (current_server -> ps_display_mode == 13)
  313.     return ((user2.u_utime + user2.u_stime) -
  314.         (user1.u_utime + user1.u_stime));
  315.       else
  316.     return (((user2.u_utime + user2.u_stime) -
  317.          (old_user2.u_utime + old_user2.u_stime)) -
  318.         ((user1.u_utime + user1.u_stime) -
  319.          (old_user1.u_utime + old_user1.u_stime)));
  320.     }
  321.   else
  322.     {
  323.       if (current_server -> ps_display_mode == 13)
  324.     return ((user1.u_utime + user1.u_stime) -
  325.         (user2.u_utime + user2.u_stime));
  326.       else
  327.     return (((user1.u_utime + user1.u_stime) -
  328.          (old_user1.u_utime + old_user1.u_stime)) -
  329.         ((user2.u_utime + user2.u_stime) -
  330.          (old_user2.u_utime + old_user2.u_stime)));
  331.  
  332.     }
  333.  
  334. }                /* end of ppproc_ucpu_scpu_compare */
  335.  
  336. /*+-------------------------------------------------------------------------
  337.     ppproc_scpu_compare(ppp1,ppp2)
  338. --------------------------------------------------------------------------*/
  339. ppproc_scpu_compare (ppp1, ppp2)
  340.      struct my_proc_struct **ppp1;
  341.      struct my_proc_struct **ppp2;
  342. {
  343.   struct my_user_struct user1;
  344.   struct my_user_struct user2;
  345.   struct my_user_struct old_user1;
  346.   struct my_user_struct old_user2;
  347.   int             i, j, k, l;
  348.   i = get_user (&(**ppp1), &user1);
  349.  
  350.   j = get_user (&(**ppp2), &user2);
  351.  
  352.   k = get_old_user (&(**ppp1), &old_user1);
  353.  
  354.   l = get_old_user (&(**ppp2), &old_user2);
  355.  
  356.  
  357.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  358.     return (0);
  359.   else if (((*ppp1) -> p_pid == 32767) || (!i))
  360.     return (1);
  361.   else if (((*ppp2) -> p_pid == 32767) || (!j))
  362.     return (-1);
  363.  
  364.   if (current_server -> ps_cpu_sort_order == 1)
  365.     {
  366.       if (current_server -> ps_display_mode == 13)
  367.     return (user2.u_stime - user1.u_stime);
  368.       else
  369.     return ((user2.u_stime - old_user2.u_stime) -
  370.         (user1.u_stime - old_user1.u_stime));
  371.     }
  372.   else
  373.     {
  374.       if (current_server -> ps_display_mode == 13)
  375.     return (user1.u_stime - user2.u_stime);
  376.       else
  377.     return ((user1.u_stime - old_user1.u_stime) -
  378.         (user2.u_stime - old_user2.u_stime));
  379.  
  380.     }
  381.  
  382. }                /* end of ppproc_scpu_compare */
  383.  
  384. /*+-------------------------------------------------------------------------
  385.     ppproc_size_compare(ppp1,ppp2)
  386. --------------------------------------------------------------------------*/
  387. ppproc_size_compare (ppp1, ppp2)
  388.      struct my_proc_struct **ppp1;
  389.      struct my_proc_struct **ppp2;
  390. {
  391.   struct my_user_struct user1;
  392.   struct my_user_struct user2;
  393.   int             i, j;
  394.  
  395.   i = get_user (&(**ppp1), &user1);
  396.  
  397.   j = get_user (&(**ppp2), &user2);
  398.  
  399.  
  400.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  401.     return (0);
  402.   else if (((*ppp1) -> p_pid == 32767) || (!i))
  403.     return (1);
  404.   else if (((*ppp2) -> p_pid == 32767) || (!j))
  405.     return (-1);
  406.  
  407.   if (current_server -> ps_cpu_sort_order == 1)
  408.     return ((user2.u_dsize + user2.u_ssize) -
  409.         (user1.u_dsize + user1.u_ssize));
  410.   else
  411.     return ((user1.u_dsize + user1.u_ssize) -
  412.         (user2.u_dsize + user2.u_ssize));
  413.  
  414.  
  415. }                /* end of ppproc_size_compare */
  416.  
  417. /*+-------------------------------------------------------------------------
  418.     ppproc_tty_compare(ppp1,ppp2)
  419. --------------------------------------------------------------------------*/
  420. ppproc_tty_compare (ppp1, ppp2)
  421.      struct my_proc_struct **ppp1;
  422.      struct my_proc_struct **ppp2;
  423. {
  424.  
  425.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  426.     return (0);
  427.   else if ((*ppp1) -> p_pid == 32767)
  428.     return (1);
  429.   else if ((*ppp2) -> p_pid == 32767)
  430.     return (-1);
  431.  
  432.   return (strcmp ((*ppp1) -> tty, (*ppp2) -> tty));
  433.  
  434. }                /* end of ppproc_tty_compare */
  435.  
  436. /*+-------------------------------------------------------------------------
  437.     ppproc_cmd_compare(ppp1,ppp2)
  438. --------------------------------------------------------------------------*/
  439. ppproc_cmd_compare (ppp1, ppp2)
  440.      struct my_proc_struct **ppp1;
  441.      struct my_proc_struct **ppp2;
  442. {
  443.   struct my_user_struct user1;
  444.   struct my_user_struct user2;
  445.   int             i, j;
  446.  
  447.   i = get_user (&(**ppp1), &user1);
  448.  
  449.   j = get_user (&(**ppp2), &user2);
  450.  
  451.  
  452.   if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
  453.     return (0);
  454.   else if ((*ppp1) -> p_pid == 32767)
  455.     return (1);
  456.   else if ((*ppp2) -> p_pid == 32767)
  457.     return (-1);
  458.  
  459.   if (current_server -> ps_cpu_sort_order == 1)
  460.     return (strcmp (user2.u_psargs, user1.u_psargs));
  461.   else
  462.     return (strcmp (user1.u_psargs, user2.u_psargs));
  463.  
  464. }                /* end of ppproc_cmd_compare */
  465.  
  466. #define PROC_Y        1
  467. #define PROC_X        0
  468. #define UID_X        2
  469. #define PID_X        12
  470. #define CPU_X        18
  471. #define PRI_X        22
  472. #define NICE_X        26
  473. #define UTIME_X        29
  474. #define STIME_X        36
  475. #define SIZE_X        43
  476. #define TTY_X        48
  477. #define CMD_X        52
  478.  
  479. /*+-------------------------------------------------------------------------
  480.     display_proc_stat(x,y,iproc)
  481. 00000000001111111111222222222233333333334444444444555555555566666666667777777777
  482. 01234567890123456789012345678901234567890123456789012345678901234567890123456789
  483. S     USER   PID  CPU PRI NI  UCPU   SCPU  SIZE TTY CMD
  484. #!########X ##### ### ### ## ###### ###### #### ### ########
  485. --------------------------------------------------------------------------*/
  486. void
  487. display_proc_stat (window, display, gc, DrawAreaXYWH, x, y, pixmap, iproc)
  488.      Window          window;
  489.      Display        *display;
  490.      GC              gc;
  491.      XWindowAttributes DrawAreaXYWH;
  492.      int             x;
  493.      int             y;
  494.      Pixmap          pixmap;
  495.      register int    iproc;
  496. {
  497.  
  498.   int             x2 = x;
  499.   register struct my_proc_struct *tproc = current_server -> pprocs[iproc];
  500.   struct my_proc_struct *oproc = current_server -> poldprocs[iproc];
  501.   int             got_user = 0;
  502.   int             got_old_user = 0;
  503.   char           *p_stat_str = " sRzdipx";    /* dependent on values of
  504.                          * SSLEEP etc */
  505.   char           *cptr;
  506.   char            s80[80];
  507.   int             fwidth = FWIDTH;
  508.   unsigned long   pixel;
  509.  
  510.  
  511.   pixel = colorPScpuIdle.pixel;
  512.  
  513.   got_user = get_user (tproc, &user);
  514.   got_old_user = get_old_user (tproc, &old_user);
  515.  
  516.   if ((tproc -> p_stat == SRUN) && !(tproc -> p_flag & SLOAD))
  517.     pixel = colorPScpuRunning.pixel;    /* Do we really need this?? */
  518.   else if (tproc -> p_stat == SRUN)
  519.     pixel = colorPScpuRunning.pixel;
  520.   else if (got_user)
  521.     {
  522.       if (got_old_user)
  523.     {
  524.       if ((old_user.u_utime + old_user.u_stime) !=
  525.           (user.u_utime + user.u_stime))
  526.         pixel = colorPScpuActive.pixel;
  527.  
  528.     }
  529.       else
  530.     pixel = colorPScpuNew.pixel;
  531.  
  532.     }
  533.  
  534.  
  535. /*
  536.  * Clear the line.....
  537.  */
  538.  
  539.   XSetForeground (display, gc, background);
  540.   XFillRectangle (display, pixmap, gc,0, y,
  541.           current_server -> SEPERATE_WINDOWS_LIST[BUTTON_ps_cpu].draw_width,
  542.                   FHEIGHT);
  543.  
  544.  
  545. /*
  546.  * Display process flag
  547.  */
  548.  
  549.   s80[0] = p_stat_str[tproc -> p_stat];
  550.   s80[1] = 0;
  551.   x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  552.   s80[0] = (tproc -> p_flag & SLOAD) ? ' ' : 'S';
  553.   x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  554.  
  555. /*
  556.  * Display user name
  557.  */
  558.  
  559.   (void) sprintf (s80, "%8s", tproc -> name);
  560.   x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  561.  
  562.  
  563. /*
  564.  * Display set uid
  565.  */
  566.  
  567.   s80[0] = (tproc -> p_uid != tproc -> p_suid) ? '#' : ' ';
  568.   s80[1] = ' ';
  569.   s80[2] = 0;
  570.   x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  571.  
  572. /*
  573.  * Display pid
  574.  */
  575.  
  576.   (void) sprintf (s80, "%5d ", tproc -> p_pid);
  577.   x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  578.  
  579. /*
  580.  * Display cpu
  581.  */
  582.  
  583.   (void) sprintf (s80, "%3u ", tproc -> p_cpu);
  584.   x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  585.  
  586. /*
  587.  * Display pri
  588.  */
  589.  
  590.   (void) sprintf (s80, "%3u ", tproc -> p_pri);
  591.   x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  592.  
  593. /*
  594.  * Display nice
  595.  */
  596.  
  597.   (void) sprintf (s80, "%2d ", tproc -> p_nice);
  598.   x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  599.  
  600. /*
  601.  * Display cpu times
  602.  */
  603.  
  604.  
  605.  
  606.  
  607.  
  608. /* since not saving user area, always update fields from it */
  609.  
  610.   if (got_user)
  611.     {
  612.       if (current_server -> ps_display_mode == 13)
  613.     {
  614.  
  615.       if (current_server -> ps_cpu_time_mode == 0)
  616.         {
  617.           strcpy (s80, get_cpu_time_str (user.u_utime));
  618.           strcat (s80, " ");
  619.           strcat (s80, get_cpu_time_str (user.u_stime));
  620.           strcat (s80, " ");
  621.           strcat (s80, get_cpu_time_str (user.u_utime + user.u_stime));
  622.           strcat (s80, " ");
  623.           x2 += disp_info_text (window, display, gc, DrawAreaXYWH,
  624.                     x2, y, pixmap, pixel, s80);
  625.         }
  626.       else if (current_server -> ps_cpu_time_mode == 1)
  627.         {
  628. /*
  629. fprintf(stdout,"Boot_time = %ld\n",current_server -> boot_time);
  630. fprintf(stdout,"user.u_utime %ld\n",user.u_utime);
  631. fprintf(stdout,"user.u_utime * 100 / boot_time %ld\n",
  632.  (user.u_utime * 100 ) /
  633.                  current_server -> boot_time);
  634. fprintf(stdout,"FLOAT user.u_utime * 100 / boot_time %f\n",
  635.  (user.u_utime * 100 ) /
  636.                  current_server -> boot_time);
  637. */
  638.  
  639.           sprintf (s80, " %5.2f  %5.2f  %5.2f ", (
  640.                           (float) (user.u_utime * 100) /
  641.                            current_server -> boot_time),
  642.                (
  643.              (float) (user.u_stime * 100) /
  644.              current_server -> boot_time),
  645.                (
  646.              (float) ((user.u_utime + user.u_stime) * 100) /
  647.              current_server -> boot_time));
  648.  
  649.           x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  650.         }
  651.  
  652.  
  653.     }
  654.       else
  655.     {
  656.  
  657.  
  658.       total_ps_ticks += (user.u_utime - old_user.u_utime) +
  659.                                 (user.u_stime - old_user.u_stime);
  660.  
  661.       if (current_server -> ps_cpu_time_mode == 2)
  662.         {
  663.           if (got_old_user)
  664.         (void) sprintf (s80, "%6d %6d %6d ",
  665.                 user.u_utime - old_user.u_utime,
  666.                 user.u_stime - old_user.u_stime,
  667.                 (user.u_utime - old_user.u_utime) +
  668.                 (user.u_stime - old_user.u_stime));
  669.           else
  670.         (void) sprintf (s80, "%6d %6d %6d ",
  671.                 user.u_utime,
  672.                 user.u_stime,
  673.                 (user.u_utime) +
  674.                 (user.u_stime));
  675.  
  676.           x2 += disp_info_text (window, display, gc,
  677.                     DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  678.         }
  679.       else if (current_server -> ps_cpu_time_mode == 1)
  680.         {
  681.           if (got_old_user)
  682.         sprintf (s80, " %5.2f  %5.2f  %5.2f ", (
  683.              (float) ((user.u_utime - old_user.u_utime) * 100) /
  684.  
  685.                    ((current_server -> StatPeriod_msec / 1000) *
  686.                 current_server -> hz)),
  687.  
  688.              (
  689.              (float) ((user.u_stime - old_user.u_stime) * 100) /
  690.                (((float) current_server -> StatPeriod_msec / 1000) *
  691.             current_server -> hz)),
  692.  
  693.              (
  694.                (float) (((user.u_utime - old_user.u_utime) +
  695.                  (user.u_stime - old_user.u_stime)) * 100) /
  696.                (((float) current_server -> StatPeriod_msec / 1000) *
  697.             current_server -> hz)));
  698.           else
  699.  
  700.         sprintf (s80, " %5.2f  %5.2f  %5.2f ", (
  701.                         (float) ((user.u_utime) * 100) /
  702.  
  703.                    ((current_server -> StatPeriod_msec / 1000) *
  704.                 current_server -> hz)),
  705.  
  706.              (
  707.                (float) ((user.u_stime) * 100) /
  708.                (((float) current_server -> StatPeriod_msec / 1000) *
  709.             current_server -> hz)),
  710.  
  711.              (
  712.                (float) (((user.u_utime) +
  713.                      (user.u_stime)) * 100) /
  714.                (((float) current_server -> StatPeriod_msec / 1000) *
  715.             current_server -> hz)));
  716.  
  717.           x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  718.         }
  719.     }
  720.  
  721.  
  722.       (void) sprintf (s80, "%4lu ",
  723.               (ctob (user.u_dsize + user.u_ssize)) / BSIZE);
  724.  
  725.       x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  726.     }
  727.   else
  728.     x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, "------ ------ ------ ---- ");
  729.  
  730.  
  731. /*
  732.  * Display tty
  733.  */
  734.  
  735.   (void) sprintf (s80, "%3.3s ", tproc -> tty);
  736.   x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
  737.  
  738. /*
  739.  * Need to change to 200 TO DiplayWidth - x2 perhaps....
  740.  *
  741.  * FIX THIS>.....
  742.  */
  743. /*
  744.       XClearArea (display, window, x2, y, FWIDTH * 200, FHEIGHT, 0);
  745. */
  746.  
  747.   XSetForeground (display, gc, background);
  748.   XFillRectangle (display, pixmap, gc, x2, y,
  749.       current_server -> SEPERATE_WINDOWS_LIST[BUTTON_ps_cpu].width - x2,
  750.           FHEIGHT);
  751.  
  752.  
  753.  
  754.   XSetForeground (display, gc, pixel);
  755.   if (got_user)
  756.     {
  757.       XDrawString (display, pixmap, gc, x2, y + FASCENT,
  758.            user.u_psargs, strlen (user.u_psargs));
  759.     }
  760.   else
  761.     {
  762.       switch (tproc -> p_stat)
  763.     {
  764.     case SZOMB:
  765.       cptr = "<zombie>";
  766.       break;
  767.     case SXBRK:
  768.       cptr = "<xbreak>";
  769.       break;
  770.     case SIDL:
  771.       cptr = "<in creation>";
  772.       break;
  773.     default:
  774.       cptr = "<swap in progress>";
  775.     }
  776. /*
  777.       XDrawString (display, window, gc, x2, y + FASCENT, cptr, strlen (cptr));
  778. */
  779.       XDrawString (display, pixmap, gc, x2, y + FASCENT, cptr, strlen (cptr));
  780.     }
  781.  
  782.  
  783. }                /* end of display_proc_stat */
  784.  
  785. /*+-------------------------------------------------------------------------
  786.     update_ps_cpu (server_pointer)
  787. --------------------------------------------------------------------------*/
  788. void
  789. update_ps_cpu (server_pointer)
  790.      struct NetworkXswStruct *server_pointer;
  791.  
  792. {
  793.  
  794.   Window          window = server_pointer -> 
  795.                 SEPERATE_WINDOWS_LIST[BUTTON_ps_cpu].window;
  796.   Display        *display = server_pointer -> 
  797.                 SEPERATE_WINDOWS_LIST[BUTTON_ps_cpu].display;
  798.   GC              gc = server_pointer -> 
  799.                 SEPERATE_WINDOWS_LIST[BUTTON_ps_cpu].gc;
  800.   Pixmap          pixmap = server_pointer -> 
  801.                 SEPERATE_WINDOWS_LIST[BUTTON_ps_cpu].pixmap;
  802.  
  803.   int             x = 0;
  804.   int             y = 0;
  805.  
  806.  
  807.   register int    iproc;
  808.   int             fheight = FHEIGHT;
  809.   int             yl1 = y + (FASCENT / 2);
  810.   int             i;
  811.   int             current_ps_number = 0;
  812.   int             got_user;
  813.   int             got_old_user;
  814.  
  815.   struct my_proc_struct *tproc;
  816.  
  817.  
  818. /*
  819.  * Create the Label widgets if neccesary, incresing the number if neccesary...
  820.  */
  821.  
  822.   sort_procs (BUTTON_ps_cpu);
  823.  
  824.   y = 0;
  825.  
  826.   total_ps_ticks = 0;
  827.   if (current_server -> ps_display_mode == 13)
  828.     {
  829.       for (iproc = 0; iproc < current_server -> nprocs; iproc++)
  830.     {
  831.       display_proc_stat (window, display, gc, DrawAreaXYWH,
  832.                  x, y + (iproc * fheight), pixmap,
  833.                  iproc);
  834.     }
  835.       y += (iproc * fheight);
  836.     }
  837.   else
  838.     {
  839.  
  840.       current_ps_number = 0;
  841.  
  842.       for (iproc = 0; iproc < current_server -> nprocs; iproc++)
  843.     {
  844.  
  845.       tproc = current_server -> pprocs[iproc];
  846.       got_user = get_user (tproc, &user);
  847.  
  848.       if (got_user)
  849.         {
  850.           if (got_old_user = get_old_user (tproc, &old_user))
  851.         {
  852.           if (((old_user.u_utime + old_user.u_stime) !=
  853.                (user.u_utime + user.u_stime)) &&
  854.               ((user.u_utime - old_user.u_utime) >= 0) &&
  855.               ((user.u_stime - old_user.u_stime) >= 0)
  856.             )
  857.             {
  858.  
  859.               display_proc_stat (window, display, gc, DrawAreaXYWH,
  860.                        x, y + (current_ps_number * fheight),
  861.                      pixmap,
  862.                      iproc);
  863.               current_ps_number++;
  864.             }
  865.  
  866.  
  867.         }
  868.         }
  869.  
  870.  
  871.     }
  872. /*
  873. fprintf(stdout,"Total ps ticks = %ld\n",total_ps_ticks);
  874. */
  875.  
  876.       y += (current_ps_number * fheight);
  877.  
  878.  
  879.     }
  880.  
  881.  
  882. /*
  883.  * Clear the remaining pixmap.....
  884.  */
  885.  
  886.   XSetForeground (display, gc, background);
  887.   XFillRectangle (display, pixmap, gc,
  888.           x, y,
  889.            current_server -> SEPERATE_WINDOWS_LIST[BUTTON_ps_cpu].draw_width,
  890.          current_server -> SEPERATE_WINDOWS_LIST[BUTTON_ps_cpu].draw_height);
  891.  
  892. }                /* end of update_ps_cpu */
  893.  
  894. /* vi: set tabstop=4 shiftwidth=4: */
  895. /* end of pscpu.c */
  896.