- staticinlinechar*
- skip_ws(constchar*p)
- while(isspace(*p))p++
- return(char*)p
- staticinlinechar*
- skip_token(constchar*p)
- while(isspace(*p))p++
- while(*p&&!isspace(*p))p++
- return(char*)p
- HostMachineInfo::HostMachineInfo():valid(1)
- charbuffer[4096+1]
- intfd,len
- char*p
- structstatfssb
- if(statfs(PROCFS,&sb)<0||sb.f_type! = PROC_SUPER_MAGIC)
- fprintf(stderr,"procfilesystemnotmountedon"PROCFS"\n")
- valid = 0
- return
- cpus = 0
- fd = open(CPUINFO,O_RDONLY)
- len = read(fd,buffer,sizeof(buffer)-1)
- close(fd)
- buffer[len] = '\0'
- p = buffer
- toendsoflines*/
- while(*p)
- if(!strncmp(p,"processor",9))++cpus
- p = strchr(p,'\n')
- if(*p = ='\n')++p
- fs/proc/proc_misc.cinthekernelsourcetree*/
- fd = open(MEMINFO,O_RDONLY)
- len = read(fd,buffer,sizeof(buffer)-1)
- close(fd)
- buffer[len] = '\0'
- intret
- unsignedlongmem_total,swp_total
- p = strstr(buffer,"MemTotal:")
- if((ret = sscanf(p,"MemTotal:%lukB\n",&mem_total))!=1)
- cerr<<"ErrorparsingMemTotalin/proc/meminfo\n"
- memory_total = mem_total
- p = strstr(buffer,"SwapTotal:")
- if((ret = sscanf(p,"SwapTotal:%lukB\n",&swp_total))!=1)
- cerr<<"ErrorparsingSwapTotalin/proc/meminfo\n"
- swap_total = swp_total
- voidHostMachineInfo::update_info()
- charbuffer[4096+1]
- intfd,len
- char*p
- intret
- unsignedlongmem_total,mem_free,swp_total,swp_free
- fd = open(MEMINFO,O_RDONLY)
- len = read(fd,buffer,sizeof(buffer)-1)
- close(fd)
- buffer[len] = '\0'
- p = strstr(buffer,"MemTotal:")
- if((ret = sscanf(p,"MemTotal:%lukB\nMemFree:%lukB\n",
- &mem_total,&mem_free))! = 2)
- cerr<<"ErrorparsingMemTotalandMemFreein/proc/meminfo\n"
- memory_total = mem_total
- memory_free = mem_free
- memory_used = memory_total-memory_free
- p = strstr(buffer,"SwapTotal:")
- if((ret = sscanf(p,"SwapTotal:%lukB\nSwapFree:%lukB\n",
- &swp_total,&swp_free))! = 2)
- cerr<<"ErrorparsingSwapTotalandSwapFreein/proc/meminfo\n"
- swap_total = swp_total
- swap_free = swp_free
- swap_used = swap_total-swap_free