Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!rochester!kodak!gizzmo!lazlo!mobile!dave From: dave@mobile.UUCP (David C. Rein) Newsgroups: comp.unix.xenix Subject: Re: lload for xenix Summary: 'uptime.c' for lload.c Keywords: lload xenix Lars_Pensj Message-ID: <170@mobile.UUCP> Date: 31 May 89 18:56:53 GMT References: <30067@conexch.UUCP> Lines: 102 Thank you very much, Lars, for putting lload.c onto the net!! I just happened to of been looking for such a program!! Starting it up in /etc/rc, and with a small modification, I used it to develop an 'uptime' command for Xenix (maybe there is already one out there, but, I didn't know about it). Anyway, I'd thought that anyone that found a use for lload.c might alos find a use for uptime.c. ----------------------- cut here for uptime.c ------------------------ /* (set ts=4) This program will read the information written by the lload.c program, and display it in a 'ruptime' format. The lload.c program was written by Lars Pensj from Myab Gothenburg, Sweden, and was distributed in alt.sources. A modified version for Xenix was developed by Sanford Zelkovitz. The following changes need to be made to the lload.c program: double av[3] = { 0.0, 0.0, 0.0 }; -- double av[4] = { 0.0, 0.0, 0.0, 0.0 }; and if (write(loadfile, (char *)av, sizeof av) != sizeof av) { perror(argv[0]); exit(1); } -- av[3] += sleeping; if (write(loadfile, (char *)av, sizeof av) != sizeof av) { perror(argv[0]); exit(1); } Compile: cc -o uptime uptime.c Created on 5/29 by David C. Rein (uunet!ism780c!kodak!gizzmo!lazlo!mobile!dave) */ #include #include #include #include #include #define LOADAV "/etc/loadav" /* Data filename */ main() { double av[4]; /* Load information */ int fd; /* Information file FD */ int minutes, hours; /* Hours and minutes up */ double days,temp; /* Days up, and calc temp*/ struct utmp *tstr; /* Pointer to utmp struct*/ int users = 0; /* Users logged in */ struct utsname name; /* System nodename struct*/ if ( (fd = open(LOADAV,O_RDONLY)) < 0 ) { perror(LOADAV); /* Can't open info file */ exit(1); } if ( read(fd, &av[0], sizeof(av)) != sizeof ( av )) { perror("Invalid data file"); /* Bad data in file */ exit( 1 ); } close(fd ); temp = (double)3600 * (double)24; /* Calculate constants */ minutes = (int)((int)(av[3] / 60 ) % 60); /* Calculate minutes */ hours = (int)((int)(av[3] / 3600 ) % 24); /* Calculate hours */ days = (av[3] / temp); /* Calculate days */ while ( (tstr = (struct utmp *)getutent()) != NULL ) { if ( !(tstr->ut_name[0] == 0 || !strncmp(tstr->ut_name,"LOGIN",5))) { users++; /* If not LOGIN or null username, real user */ } } if ( uname(&name) < 0 ) { perror("Unable to get system name"); /* Can't get system name*/ exit( 1 ); } printf("%-8.8s up", name.nodename); /* Print system name */ if ( (int)days > (int)0 ) printf("%3d+", (int)days); else /* Print days up */ printf(" "); printf("%.2d:%.2d,", hours, minutes); /* Print hours:mins up */ printf("%4d users,", users); /* # of logged in users */ printf(" load %4.2f, %4.2f, %4.2f\n",av[0], av[1], av[2]);/*load */ } --- Dave Rein ----------------------------------\ /----------------------------------------- UUCP: ..!kodak!gizzmo!lazlo!\ \/ "It just goes to show what you can do mobile!dave /\ if you're a total psychotic" Domain: dcr0801@ritcv / \ -- Woody Allen ---------------------------------/ \----------------------------------------