Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!ames!ucbcad!ucbvax!unl::spa!psi From: psi@unl::spa (Salvador Pinto Abreu) Newsgroups: comp.windows.x Subject: xrload (part 4 of 6) Message-ID: <8708131203.AA05104@decwrl.dec.com> Date: Thu, 13-Aug-87 14:57:00 EDT Article-I.D.: decwrl.8708131203.AA05104 Posted: Thu Aug 13 14:57:00 1987 Date-Received: Sat, 15-Aug-87 08:37:51 EDT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: world Organization: The ARPA Internet Lines: 118 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh get-stats.c <<'END_OF_get-stats.c' X/**************************************************************************/ X/* */ X/* Get system statistics. */ X/* */ X/**************************************************************************/ X X#include "xrload.h" X Xint pid; /* Gets child process id */ Xint iofd[2]; /* Sincronization pipe */ X Xint get_stats (stats) X sys_stat *stats; X{ X if (pipe (iofd) < 0) { X perror ("pipe"); X exit (1); X } X X if ((pid = fork ()) < 0) X perror ("fork"); X else if (pid == 0) { /* Child: exec ruptime */ X dup2 (iofd[1], 1); /* stdout to pipe */ X execl ("/usr/ucb/ruptime", "ruptime", 0); X perror ("can't exec /usr/ucb/ruptime"); X exit (1); X } X else { /* Parent: parse the stuff */ X static char hstatus[8], junk[8]; X union wait status; X int nh = 0, nf; X FILE *pfile; X X close (iofd[1]); X pfile = fdopen (iofd[0], "r"); X X for (;;) { X nf = fscanf (pfile, "%s %s %s %d %s load %f, %f, %f", X stats[nh].sys_name, hstatus, stats[nh].how_long, X &stats[nh].users, junk, X &stats[nh].load_average[0], X &stats[nh].load_average[1], X &stats[nh].load_average[2]); X if (dflag) X printf ("sys %d(%d): %s %s %s %du, %g %g %g\n", nh, nf, X stats[nh].sys_name, hstatus, stats[nh].how_long, X stats[nh].users, X stats[nh].load_average[0], X stats[nh].load_average[1], X stats[nh].load_average[2]); X if (nf < 3) break; X stats[nh].how_long[strlen(stats[nh].how_long)-1] = '\0'; X stats[nh].state = strcmp(hstatus, "up")? DOWN: UP; X if (all_hosts) X nh++; X else { X register int i = 0; X while (host_names[i] && X !streq(stats[nh].sys_name, host_names[i])) X i++; X if (host_names[i]) X nh++; X } X } X X stats[nh].sys_name[0] = '\0'; X X fclose (pfile); X wait (&status); X return (nh); X } X} END_OF_get-stats.c if test 1791 -ne `wc -c