home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3297 / load.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-07  |  1.2 KB  |  57 lines

  1. /* History:
  2. 5/1/91 DJB baseline public domain
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <time.h>
  7. #include <utmp.h>
  8. #include "avenrun.h"
  9. #include "boottime.h"
  10. #include "strerr.h"
  11.  
  12. #ifndef UTMP_FILE
  13. #define UTMP_FILE "/etc/utmp"
  14. #endif
  15.  
  16. static char progname[] = "load";
  17.  
  18. main()
  19. {
  20.  double *av;
  21.  long now;
  22.  long boottime;
  23.  FILE *fi;
  24.  struct utmp ut;
  25.  int numusers;
  26.  
  27.  if (avenruninit() == -1)
  28.   { fprintf(stderr,"%s: %s\n",progname,strerr(avenrunstrerr)); exit(1); }
  29.  if (boottimeinit() == -1)
  30.   { fprintf(stderr,"%s: %s\n",progname,strerr(boottimestrerr)); exit(1); }
  31.  
  32.  if (!(av = getavenrun()))
  33.   { fprintf(stderr,"%s: %s\n",progname,strerr(avenrunstrerr)); exit(1); }
  34.  if (!(boottime = getboottime()))
  35.   { fprintf(stderr,"%s: %s\n",progname,strerr(boottimestrerr)); exit(1); }
  36.  
  37.  if (!(fi = fopen(UTMP_FILE,"r")))
  38.   { fprintf(stderr,"%s: cannot open %s",progname,UTMP_FILE); exit(1); }
  39.  numusers = 0;
  40.  while (fread((char *) &ut,sizeof(ut),1,fi))
  41.    if (*ut.ut_name)
  42.      ++numusers;
  43.  /* don't bother closing fi */
  44.  
  45.  (void) time(&now);
  46.  
  47.  printf("%15.15s, ",ctime(&now) + 4);
  48.  printf("booted %15.15s, %d users, load %.2f %.2f %.2f\n"
  49.         ,ctime(&boottime) + 4
  50.     ,numusers
  51.     ,av[0]
  52.     ,av[1]
  53.     ,av[2]
  54.        );
  55.  exit(0);
  56. }
  57.