#include #include#include#include
#define MAXBUFSIZE 1024
#define WAIT_SECOND 3 //暂停时间,单位为“秒”typedefstructoccupy
{char name[20];
unsignedintuser;
unsignedintnice;
unsignedintsystem;
unsignedintidle;
} CPU_OCCUPY ;
typedefstructPACKED
{char name[20];longtotal;char name2[20];long free;
}MEM_OCCUPY;floatg_cpu_used;int cpu_num; //定义一个全局的int类型cup_num
void cal_occupy(CPU_OCCUPY *, CPU_OCCUPY *);void get_occupy(CPU_OCCUPY *);void get_mem_occupy(MEM_OCCUPY *) ;floatget_io_occupy();void get_disk_occupy(char **reused);void getCurrentDownloadRates(long int *save_rate);intmain(){
CPU_OCCUPY ocpu,ncpu;
MEM_OCCUPY mem;//获取cpu核数
cpu_num =sysconf(_SC_NPROCESSORS_ONLN);
printf("cpu mum:%d",cpu_num);//获取cpu使用率
get_occupy(&ocpu);
sleep(1);
get_occupy(&ncpu);