struct rpm{
long curr_stime;
long prev_stime;
long curr_utime;
long prev_utime;
}cpuinfo[CPUNUM];
void cpuagent();
void console();
/**************************************
linux system management
mfkwmfk 2005.7.13
***************************************/
#include "rpm.h"
void cpuagent(){
FILE *fn;
char tempchar1[256];
char tempchar2[256];
char tempchar3[256];
char tempchar4[256];
char tempchar5[256];
long stime;
long utime;
long ulowtime;
long temp1;
char buf[256];
do{
int i=0;
bzero(buf,256);
fn=fopen("/proc/stat","r");
fgets(buf,256,fn);
for(;i<CPUNUM;i++){
bzero(buf,256);
bzero(tempchar1,256);
bzero(tempchar2,256);
bzero(tempchar3,256);
bzero(tempchar4,256);
bzero(tempchar5,256);
fgets(buf,256,fn);
sscanf(buf,"%s %s %s %s %s",tempchar1,tempchar2,tempchar3,tempchar4,tempchar5);
utime=atoi(tempchar3);
ulowtime=atoi(tempchar4);
stime=atoi(tempchar5);
utime+=ulowtime;
cpuinfo[i].prev_stime=cpuinfo[i].curr_stime;
cpuinfo[i].prev_utime=cpuinfo[i].curr_utime;
cpuinfo[i].curr_stime=stime;
cpuinfo[i].curr_utime=utime;
}
fclose(fn);
sleep(2);
} while(1);
}
void console(){
while (1){
int i=0;
int j;
printf("cpu number : %d\n",CPUNUM);
for (;i<CPUNUM;i++){
int j=i+1;
printf("The %dth cpu current user time: %d\n",j,cpuinfo[i].curr_utime);
printf("The %dth cpu previous user time: %d\n",j,cpuinfo[i].prev_utime);
printf("The %dth cpu current system time: %d\n",j,cpuinfo[i].curr_stime);
printf("The %dth cpu previous system time: %d\n",j,cpuinfo[i].prev_stime);
printf("\n");
}
sleep(2);
}
}
do{
printf("Choose the cmd: \n");
printf(" [1]show me the cpu info\n");
void console(){
while (1){
int i=0;
int j;
printf("cpu number : %d\n",CPUNUM);
for (;i<CPUNUM;i++){
int j=i+1;
printf("The %dth cpu current user time: %d\n",j,cpuinfo[i].curr_utime);
printf("The %dth cpu previous user time: %d\n",j,cpuinfo[i].prev_utime);
printf("The %dth cpu current system time: %d\n",j,cpuinfo[i].curr_stime);
printf("The %dth cpu previous system time: %d\n",j,cpuinfo[i].prev_stime);
printf("\n");
}
sleep(2);
}
}