#include #include #include #include #include #if 0 int sysinfo(struct sysinfo *info); DESCRIPTION sysinfo returns information in the following structure: struct sysinfo { long uptime; /* Seconds since boot */ unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ unsigned long totalram; /* Total usable main memory size */ unsigned long freeram; /* Available memory size */ unsigned long sharedram; /* Amount of shared memory */ unsigned long bufferram; /* Memory used by buffers */ unsigned long totalswap; /* Total swap space size */ unsigned long freeswap; /* swap space still available */ unsigned short procs; /* Number of current processes */ char _f[22]; /* Pads structure to 64 bytes */ }; #endif int main( int argc, char **argv ) { struct sysinfo si; float t1,t5,t15; time_t t; char *when; int imat; char s[256]; if ( argc!=2 ) { fprintf(stderr,"Usage: %s outputnext\n",argv[0]); return(1); } imat= atoi(argv[1]); while(1) { time(&t); when=ctime(&t); sysinfo(&si); t1= si.loads[0]/65536.0; t5= si.loads[1]/65536.0; t15= si.loads[2]/65536.0; fprintf(stderr,"%f %f %f %s", t1,t5,t15,when ); if ( t5 < 1.1 && t1 < 1.1 ) { /* Its dead, jim. */ fprintf(stderr,"Its dead, jim. killing and restarting at %s", when ); sprintf(s,"./startem %d", imat++ ); fprintf(stderr,"%s\n", s); system(s); sleep(10); } sleep(60*5); } }