home *** CD-ROM | disk | FTP | other *** search
- /* History:
- 5/1/91 DJB baseline public domain
- */
-
- #include <stdio.h>
- #include <time.h>
- #include <utmp.h>
- #include "avenrun.h"
- #include "boottime.h"
- #include "strerr.h"
-
- #ifndef UTMP_FILE
- #define UTMP_FILE "/etc/utmp"
- #endif
-
- static char progname[] = "load";
-
- main()
- {
- double *av;
- long now;
- long boottime;
- FILE *fi;
- struct utmp ut;
- int numusers;
-
- if (avenruninit() == -1)
- { fprintf(stderr,"%s: %s\n",progname,strerr(avenrunstrerr)); exit(1); }
- if (boottimeinit() == -1)
- { fprintf(stderr,"%s: %s\n",progname,strerr(boottimestrerr)); exit(1); }
-
- if (!(av = getavenrun()))
- { fprintf(stderr,"%s: %s\n",progname,strerr(avenrunstrerr)); exit(1); }
- if (!(boottime = getboottime()))
- { fprintf(stderr,"%s: %s\n",progname,strerr(boottimestrerr)); exit(1); }
-
- if (!(fi = fopen(UTMP_FILE,"r")))
- { fprintf(stderr,"%s: cannot open %s",progname,UTMP_FILE); exit(1); }
- numusers = 0;
- while (fread((char *) &ut,sizeof(ut),1,fi))
- if (*ut.ut_name)
- ++numusers;
- /* don't bother closing fi */
-
- (void) time(&now);
-
- printf("%15.15s, ",ctime(&now) + 4);
- printf("booted %15.15s, %d users, load %.2f %.2f %.2f\n"
- ,ctime(&boottime) + 4
- ,numusers
- ,av[0]
- ,av[1]
- ,av[2]
- );
- exit(0);
- }
-