home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / linux / 23762 < prev    next >
Encoding:
Text File  |  1993-01-12  |  2.0 KB  |  65 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!math.fu-berlin.de!Sirius.dfn.de!olymp!plumbum!lederer
  3. From: lederer@informatik.uni-bonn.de (Sebastian Lederer)
  4. Subject: A simple xload program using proc fs
  5. Message-ID: <1993Jan12.125403.14817@olymp.informatik.uni-bonn.de>
  6. Keywords: xload
  7. Sender: usenet@olymp.informatik.uni-bonn.de
  8. Reply-To: lederer@informatik.uni-bonn.de
  9. Organization: Universit"at Bonn, Informatikinstitut, R"omerstr 154, W-5300 Bonn 1
  10. Date: Tue, 12 Jan 1993 12:54:03 GMT
  11. Lines: 52
  12.  
  13.  
  14. After some browsing in the X manuals I found that an xload program using the proc filesystem
  15. would be very easy...so here is the code. Hope some of you find it useful.
  16. The resources used should be the same as for the original xload.
  17. Please mail questions/improvements/patches to
  18. sebi@avatar.GUN.de
  19. -----------------------------------  xload.c -----------------------------------------
  20.  
  21. #define LOADAVG "/proc/loadavg"
  22. #include <stdio.h>
  23. #include <sys/param.h> /* for MAXHOSTNAMELEN */
  24. #include <X11/Intrinsic.h>
  25. #include <X11/StringDefs.h>
  26. #include <X11/Xaw/StripChart.h>
  27. #include <X11/Xaw/Label.h>
  28. #include <X11/Xaw/Paned.h>
  29.  
  30. void get_value(Widget w, XtPointer client_data, XtPointer chart_value)
  31. {
  32.     FILE *loadavg;
  33.     
  34.     if( (loadavg=fopen(LOADAVG,"r"))==NULL)
  35.         {
  36.             fprintf(stderr,"couldn't open %s",LOADAVG);
  37.             exit(1);    
  38.         }
  39.     fscanf(loadavg,"%lf", (double *) chart_value);
  40.     fclose(loadavg);
  41. }
  42.  
  43. main(int argc,char **argv)
  44. {
  45.     XtAppContext app_context;
  46.     Widget topLevel, chart,paned,label;
  47.  
  48.     char hostname[MAXHOSTNAMELEN+1];
  49.     
  50.     gethostname(hostname,MAXHOSTNAMELEN);
  51.         
  52.     topLevel = XtVaAppInitialize(&app_context,"Xload",NULL,0,&argc,
  53.             argv,NULL,NULL);
  54.     paned = XtVaCreateManagedWidget( "paned", panedWidgetClass, topLevel,
  55.                     NULL);
  56.     label = XtVaCreateManagedWidget( "label", labelWidgetClass, paned,
  57.                     "label",hostname, NULL);
  58.     chart = XtVaCreateManagedWidget ("load",stripChartWidgetClass, 
  59.             paned,NULL);
  60.     XtAddCallback(chart, XtNgetValue, get_value, 0 );
  61.     XtRealizeWidget(topLevel);
  62.     XtAppMainLoop(app_context);
  63. }
  64.  
  65.