home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!math.fu-berlin.de!Sirius.dfn.de!olymp!plumbum!lederer
- From: lederer@informatik.uni-bonn.de (Sebastian Lederer)
- Subject: A simple xload program using proc fs
- Message-ID: <1993Jan12.125403.14817@olymp.informatik.uni-bonn.de>
- Keywords: xload
- Sender: usenet@olymp.informatik.uni-bonn.de
- Reply-To: lederer@informatik.uni-bonn.de
- Organization: Universit"at Bonn, Informatikinstitut, R"omerstr 154, W-5300 Bonn 1
- Date: Tue, 12 Jan 1993 12:54:03 GMT
- Lines: 52
-
-
- After some browsing in the X manuals I found that an xload program using the proc filesystem
- would be very easy...so here is the code. Hope some of you find it useful.
- The resources used should be the same as for the original xload.
- Please mail questions/improvements/patches to
- sebi@avatar.GUN.de
- ----------------------------------- xload.c -----------------------------------------
-
- #define LOADAVG "/proc/loadavg"
- #include <stdio.h>
- #include <sys/param.h> /* for MAXHOSTNAMELEN */
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- #include <X11/Xaw/StripChart.h>
- #include <X11/Xaw/Label.h>
- #include <X11/Xaw/Paned.h>
-
- void get_value(Widget w, XtPointer client_data, XtPointer chart_value)
- {
- FILE *loadavg;
-
- if( (loadavg=fopen(LOADAVG,"r"))==NULL)
- {
- fprintf(stderr,"couldn't open %s",LOADAVG);
- exit(1);
- }
- fscanf(loadavg,"%lf", (double *) chart_value);
- fclose(loadavg);
- }
-
- main(int argc,char **argv)
- {
- XtAppContext app_context;
- Widget topLevel, chart,paned,label;
-
- char hostname[MAXHOSTNAMELEN+1];
-
- gethostname(hostname,MAXHOSTNAMELEN);
-
- topLevel = XtVaAppInitialize(&app_context,"Xload",NULL,0,&argc,
- argv,NULL,NULL);
- paned = XtVaCreateManagedWidget( "paned", panedWidgetClass, topLevel,
- NULL);
- label = XtVaCreateManagedWidget( "label", labelWidgetClass, paned,
- "label",hostname, NULL);
- chart = XtVaCreateManagedWidget ("load",stripChartWidgetClass,
- paned,NULL);
- XtAddCallback(chart, XtNgetValue, get_value, 0 );
- XtRealizeWidget(topLevel);
- XtAppMainLoop(app_context);
- }
-
-