home *** CD-ROM | disk | FTP | other *** search
- /*
- * @(#) proc.c 12.1 95/05/09 SCOINC
- */
- /***************************************************************************
- *
- * Copyright (c) 1990-1993 The Santa Cruz Operation, Inc.
- *
- * All rights reserved. No part of this program or publication may be
- * reproduced, transmitted, transcribed, stored in a retrieval system,
- * or translated into any language or computer language, in any form or
- * by any means, electronic, mechanical, magnetic, optical, chemical,
- * biological, or otherwise, without the prior written permission of:
- *
- * The Santa Cruz Operation , Inc. (408) 425-7222
- * 400 Encinal St., Santa Cruz, California 95060 USA
- *
- **************************************************************************/
- /*
- * Modification History
- *
- * S002, 27-May-93, rickra
- * Added "get ticks since boot"...
- *
- * S001, 01-Jan-93, rickra
- * Added abs to user I/O times to ensure postive number....
- * Added support for seperate windows.
- *
- * S000, 30-Sep-92, rickra
- * Added copyright and modification history
- *
- */
- /*+-------------------------------------------------------------------------
- proc.c - XSW proc table handler
- wht@n4hgf.Mt-Park.GA.US
-
- Defined functions:
- draw_update_Proc(x,y)
- initialize_Proc()
- grok_proc()
- pstat_text(pstat)
-
- --------------------------------------------------------------------------*/
- /*+:EDITS:*/
- /*:09-25-1990-05:11-wht@n4hgf-release heh-heh x0.22 preliminary */
- /*:09-20-1990-03:10-wht@n4hgf-adapt u386mon code */
-
- #include <malloc.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Intrinsic.h>
- #include <X11/Shell.h>
- #include <X11/StringDefs.h>
- #include <Xm/Xm.h>
- #include <Xm/MainW.h>
- #include <Xm/DrawingA.h>
-
- #include "include/unixincs.h"
- #include "include/resources.h"
- #include "include/xswboth.h"
- #include "include/buttons.h"
- #include "include/libkmem.h"
- #include "include/xsw.h"
-
- extern MyResources res;
-
- extern struct nlist x[];
-
- #define BX_PROCS 5
-
- int procs_per_pstat[SXBRK + 1];
- int procs_in_core;
-
- static int line_style = LineSolid;
- static int cap_style = CapButt;
- static int join_style = JoinMiter;
-
- #ifdef draw_update_Proc
- /*+-------------------------------------------------------------------------
- pstat_text(pstat)
- --------------------------------------------------------------------------*/
- char *
- pstat_text (pstat)
- char pstat;
- {
- static char errant[10];
-
- switch (pstat)
- {
- case SSLEEP:
- return ("sleep ");
- case SRUN:
- return ("run ");
- case SZOMB:
- return ("zombie");
- case SSTOP:
- return ("stop ");
- case SIDL:
- return ("idle ");
- case SONPROC:
- return ("onproc");
- case SXBRK:
- return ("xbrk ");
- }
- (void) sprintf (errant, "%06u?", (unsigned char) pstat);
- return (errant);
-
- } /* end of pstat_text */
-
- #endif
-
- /*+-------------------------------------------------------------------------
- grok_proc() - read and examine kernel process table
- --------------------------------------------------------------------------*/
- void
- grok_proc (server_pointer)
- struct NetworkXswStruct *server_pointer;
- {
- register iproc;
- register struct my_proc_struct *tproc;
- int temp = 0;
- int total_trans = 0;
- int i = 0;
- struct user tuser;
- int got_data = 0;
- int slots_in_use = 0;
-
-
- /*
- * Get ticks since boot.....
- */
-
- xsw_write (server_pointer,
- server_pointer -> FileDescriptor,
- send_boot_time,
- sizeof (int));
-
- xsw_read (server_pointer,
- server_pointer -> FileDescriptor,
- &server_pointer -> boot_time,
- sizeof (time_t));
-
-
- /*
- * Ask for process data......
- */
-
-
-
- xsw_write (server_pointer,
- server_pointer -> FileDescriptor,
- send_process_data,
- sizeof (int));
-
- /*
- * Get number of currently used process slots....
- */
-
-
- xsw_read (server_pointer,
- server_pointer -> FileDescriptor,
- &slots_in_use,
- sizeof (slots_in_use));
-
- xsw_write (server_pointer,
- server_pointer -> FileDescriptor,
- &got_data,
- sizeof (int));
-
-
-
- /*
- * Read in the processes.....
- */
-
- xsw_read (server_pointer,
- server_pointer -> FileDescriptor,
- server_pointer -> procs,
- sizeof (struct my_proc_struct) * slots_in_use);
-
- xsw_write (server_pointer,
- server_pointer -> FileDescriptor,
- &got_data,
- sizeof (int));
-
- if (server_pointer -> old_my_user != NULL)
- {
- free (server_pointer -> old_my_user);
- }
-
-
- server_pointer -> old_slots_in_use = server_pointer -> slots_in_use;
- server_pointer -> slots_in_use = slots_in_use;
-
- if (server_pointer -> slots_in_use > server_pointer -> max_slots_in_use)
- {
- server_pointer -> old_max_slots_in_use = server_pointer -> max_slots_in_use;
- server_pointer -> max_slots_in_use = server_pointer -> slots_in_use;
- }
-
- server_pointer -> old_my_user = (struct my_user_struct *)
- malloc (sizeof (struct my_user_struct) * server_pointer -> old_slots_in_use);
-
-
-
- (void) memcpy ((char *) server_pointer -> old_my_user,
- (char *) server_pointer -> my_user,
- sizeof (struct my_user_struct) * server_pointer -> old_slots_in_use);
-
-
- if (server_pointer -> my_user != NULL)
- {
- free (server_pointer -> my_user);
- }
-
-
- server_pointer -> my_user = (struct my_user_struct *)
- malloc (sizeof (struct my_user_struct) * slots_in_use);
-
- xsw_read (server_pointer,
- server_pointer -> FileDescriptor,
- server_pointer -> my_user,
- sizeof (struct my_user_struct) * slots_in_use);
-
-
- for (iproc = 0; iproc < SXBRK + 1; iproc++)
- procs_per_pstat[iproc] = 0;
- procs_in_core = 0;
-
- server_pointer -> old_procs_alive = server_pointer -> procs_alive;
- server_pointer -> procs_alive = 0;
-
- for (iproc = 0; iproc < slots_in_use; iproc++)
- {
- tproc = server_pointer -> pprocs[iproc] = (server_pointer -> procs + iproc);
-
- if (tproc -> p_stat)
- server_pointer -> procs_alive++;
-
-
- procs_per_pstat[tproc -> p_stat]++; /* count # procs in each
- * state */
-
- if (tproc -> p_flag & SLOAD) /* count # procs in memory */
- procs_in_core++;
- }
-
-
-
- } /* end of grok_proc */
-
- #ifdef draw_update_Proc
- /*+-------------------------------------------------------------------------
- draw_update_Proc(x,y)
- --------------------------------------------------------------------------*/
- void
- draw_update_Proc (x, y)
- int y;
- int x;
- {
- register istat;
- register itmp;
- char *cptr;
- char s80[80];
- int fwidth = FWIDTH;
- int fheight = FHEIGHT;
- int len;
- int x2 = x;
- int yl1 = y + (FASCENT / 2);
- int yl2 = y + (fheight / 2) - 1;
- int ys = y + FASCENT;
-
-
- if (DrawAreaXYWH.height < (y + (fheight * 2)))
- return;
-
- if (redrawing_entire_DrawArea)
- {
- cptr = "---Proc----";
- len = strlen (cptr);
- /* the "background" bar */
- XSetForeground (display, gc, colorSlate.pixel);
- XSetLineAttributes (display, gc, fheight,
- line_style, cap_style, join_style);
- XDrawLine (display, window, gc, x, yl1, x + (len * fwidth), yl1);
-
- /* draw the black line before "Proc" */
- XSetForeground (display, gc, foreground);
- XSetLineAttributes (display, gc, FASCENT / 2,
- line_style, cap_style, join_style);
- XDrawLine (display, window, gc,
- x2, yl1,
- x2 + (len = (fwidth * 3)) - FGAP, yl1);
- x2 += len;
-
- /* draw "Proc" */
- cptr = "Proc";
- XDrawString (display, window, gc, x2, ys, cptr, len = strlen (cptr));
- XDrawString (display, window, gc, x2 + 1, ys, cptr, len);
- x2 += fwidth * len;
-
- /* draw the black line after "Proc" */
- XDrawLine (display, window, gc,
- x2 + FGAP + 1, yl1,
- x2 + (len = (fwidth * 4)), yl1);
- }
- y += fheight;
-
- grok_proc ();
-
- for (istat = SSLEEP; istat <= SXBRK; istat++)
- {
- disp_info_int (window, display, gc, DrawAreaXYWH, x, y, pstat_text (istat), " %3d", procs_per_pstat[istat]);
- y += fheight;
- }
- disp_info_int (window, display, gc, DrawAreaXYWH, x, y, "total ", " %3d", procs_alive);
- y += fheight;
- disp_info_int (window, display, gc, DrawAreaXYWH, x, y, "in mem", " %3d", procs_in_core);
-
- } /* end of draw_update_Proc */
-
- #endif
- /*+-------------------------------------------------------------------------
- initialize_Proc()
- --------------------------------------------------------------------------*/
-
- initialize_Proc (server_pointer)
- struct NetworkXswStruct *server_pointer;
- {
- static char *memfail = "cannot alloc memory for proc table";
-
- #ifdef DEBUG1
- fprintf (stdout, "In initialize_Proc\n");
- #endif
- /*
- if (!(server_pointer->real_procs = (struct proc *) malloc (sizeof (struct proc) * server_pointer-> my_v -> v_proc)))
- leave_text (memfail, 1);
- */
-
-
- if (!(server_pointer -> procs = (struct my_proc_struct *) malloc (sizeof (struct my_proc_struct) * server_pointer -> my_v -> v_proc)))
- leave_text (memfail, 1);
-
-
- if (!(server_pointer -> oldprocs = (struct my_proc_struct *) malloc (sizeof (struct my_proc_struct) * server_pointer -> my_v -> v_proc)))
- leave_text (memfail, 1);
-
-
- if (!(server_pointer -> pprocs = (struct my_proc_struct **) malloc (sizeof (struct my_proc_struct *) * server_pointer -> my_v -> v_proc)))
- leave_text (memfail, 1);
-
-
- if (!(server_pointer -> poldprocs = (struct my_proc_struct **) malloc (sizeof (struct my_proc_struct) * server_pointer -> my_v -> v_proc)))
- leave_text (memfail, 1);
-
-
- } /* end of initialize_Proc */
-
- /* vi: set tabstop=4 shiftwidth=4: */
- /* end of proc.c */
-