ÏÂÃæÊÇ/procĿ¼ÏµÄÎļþ£º
apm ¸ß¼¶µçÔ´¹ÜÀíÐÅÏ¢
cmdline ÄÚºËÃüÁîÐÐ
Cpuinfo ¹ØÓÚ Cpu ÐÅÏ¢
Devices ¿ÉÒÔÓõ½µÄÉ豸£¨¿éÉ豸/×Ö·ûÉ豸£©
Dma Used DMS channels
Filesystems Ö§³ÖµÄÎļþϵͳ
Interrupts ÖжϵÄʹÓÃ
Ioports I/O ¶Ë¿ÚµÄʹÓÃ
Kcore Äں˺ËÐÄÓ¡Ïó
Kmsg ÄÚºËÏûÏ¢
Ksyms Äں˷ûºÅ±í
Loadavg ¸ºÔؾùºâ
Locks ÄÚºËËø
Meminfo ÄÚ´æÐÅÏ¢
Misc Miscellaneous
Modules ¼ÓÔØÄ£¿éÁбí
Mounts ¼ÓÔØµÄÎļþϵͳ
Partitions ϵͳʶ±ðµÄ·ÖÇø±í
Rtc Real time clock
Slabinfo Slab pool info
Stat È«ÃæÍ³¼Æ×´Ì¬±í
Swaps ¶Ô»»¿Õ¼äµÄÀûÓÃÇé¿ö
Version Äں˰汾
Uptime ϵͳÕý³£ÔËÐÐʱ¼ä
ÏÂÃæÊÇÎÒ×Ô¼ºÐ´µÃÒ»¸ö²é¿´cpuºÍÄں˰汾ÐÅÏ¢ÒÔ¼°Æô¶¯Ê±¼äµÄ³ÌÐò£º
ÒòÎªÒªÉæ¼°Îļþ¶Áд£¬ÏȽéÉÜһϼ¸¸öÎļþ¶Áдº¯Êý¡£
1)fgetc´ÓÁ÷ÖжÁȡһ¸ö×Ö·û£¬²¢Ôö¼ÓÎļþÖ¸ÕëµÄλÖ㬳£ÓëEOFÅäºÏʹÓ㬽«Á÷ÖеÄ×Ö·ûÈ«²¿¶Á³ö¡£
2)putcharÏòÖÕ¶ËÊä³öÒ»¸ö×Ö·û¡£
3)fgets(char *s, int size, FILE *stream)£¬´ÓÎļþÁ÷ÖжÁȡһÐе½sÖУ¬sizeÒ»°ãΪÊý×ésµÄ´óС£¬ÇÒsÒÔ×Ö·û'/0'½áÊø¡£
4)int feof(FILE *stream)ÅжÏÊÇ·ñÓöµ½Îļþ½áÊø£¬Èç¹ûÓöµ½Ôò·µ»Ø·ÇÁãÖµ£¬·ñÔòΪ0¡£
5)int fscanf(FILE *stream, const char *format, ...)´ÓÎļþÁ÷£¨»ò±ê×¼ÊäÈ룩ÖнøÐиñʽ»¯ÊäÈ룬Ó÷¨ÈçÏ£º[code]#include
int main()
{
int i;
char s[5];
fscanf(stdin, "%d %5[a-z]%*s", &i, s);
printf("%d %s \n", i, s);
return 0;
}[/code]Ö´Ðнá¹û£¨ÃüÁîÐÐÊäÈë99 abcdefghijk£¬ÓÉÓÚfscanfÓöµ½¿Õ¸ñºÍ»»ÐÐʱ½áÊø£¬Ôò99´æµ½i£¬abcde´æµ½s£©£º[code]#include
#include
#define LB_SIZE 80
enum TYPE{STANDARD, SHORT, LONG};
FILE *thisProcFile; //Proc open file pointer
struct timeval now; //system time date
enum TYPE reportType; //the type of observation report
char repTypeName[16];
char *lineBuf; //read out buffer
int interval; //system overload detect interval
int duration; //system overload detect duration
int iteration;
char c1, c2; //character handle uint
void getTwoTime(FILE *fp)
{
long uptime, idletime;
int day, hour,minute, second;
int m, n;
char temp[80];
m = n = 0;
int ret;
int i = 0;
char s[100][100];
int j;
while((ret=fscanf(fp, "%s", s[i])) != EOF) i++;
for(j = 0; j < i; j++)
{
printf("%s\n", s[j]);
}
uptime = atol(s[0]);
idletime = atol(s[1]);
printf("<<---------------------___________------------------------->\n");
printf("the uptime of system -----------------------------> %ld\n", uptime);
printf("the idletime of process -----------------------------> %ld\n", idletime);
printf("<<---------------------___________------------------------->\n");
/* time_t uptime_timet = uptime;
printf("xixixixixi%ld\n", uptime_timet);
char *result = ctime(&uptime_timet);
printf("hahahahahahah %s\n", result);
*/
int days;
int hours;
int minutes;
int seconds;
//uptime of system
days = (int)uptime/86400;
hours = (int)uptime%86400/3600;
minutes = (int)uptime%3600/60;
seconds = (int)uptime%3600%60;
printf("the uptime of system-------------days %d----hours %d-----minutes %d-----seconds %d----\n", days, hours, minutes, seconds);
//idletime
days = (int)idletime/86400;
hours = (int)idletime%86400/3600;
minutes = (int)idletime%3600/60;
seconds = (int)idletime%3600%60;
printf("the idletime of system-------------days %d----hours %d-----minutes %d-----seconds %d----\n", days, hours, minutes, seconds);
}
//get time from starting
void sampleTime()
{
//open timer file
FILE *fp;
if((fp=fopen("/proc/uptime", "r")) == NULL)
{
printf("not open /proc/uptime");
exit(0);
}
getTwoTime(fp);
fclose(fp);
}
void getCPUinfo()
{
FILE *cpuinfo;
char ch;
if((cpuinfo=fopen("/proc/cpuinfo","r")) == NULL)
{
printf("not open /proc/cpuinfo");
exit(0);
}
/* while((ch=fgetc(cpuinfo)) != EOF)
putchar(ch);
fclose(cpuinfo);
*/
printf("*********************cpu*******************\n");
while(!feof(cpuinfo))
{
fgets(lineBuf, LB_SIZE+1, cpuinfo);
printf("%s", lineBuf);
}
fclose(cpuinfo);
}
void getKernelVersion()
{
FILE *version;
char ch;
if((version=fopen("/proc/version","r")) == NULL)
{
printf("not open /proc/version");
exit(0);
}
printf("*****************version*************************\n");
while(!feof(version))
{
fgets(lineBuf, LB_SIZE+1, version);
printf("%s", lineBuf);
}
fclose(version);
}
int main(int argc, char *argv[])
{
lineBuf = (char *)malloc(LB_SIZE + 1);
reportType = STANDARD;
strcpy(repTypeName, "Standard");
if(argc > 1)
{
sscanf(argv[1], "%c%c", &c1, &c2);
if(c1 != '-') exit(1);
if(c2 == 'b')
{
printf("********************************Memory Info*********************************\n");
//open memory info
FILE *meminfo;
char ch;
if((meminfo=fopen("/proc/meminfo","r")) == NULL)
{
printf("not open /proc/meminfo");
exit(0);
}
while((ch=fgetc(meminfo)) != EOF)
putchar(ch);
fclose(meminfo);
printf("********************************TIME*********************************\n");
//cat the start time
sampleTime();
} else if(c2 == 'c')
{
//get cpu info and kernel version
printf("*************************CPU & kernel*************************\n");
getCPUinfo();
getKernelVersion();
}
}
}[/code]Ö´ÐУº
./main -b ²é¿´ÄÚ´æÐÅÏ¢ÒÔ¼°¾¹ý¸ñʽ»¯µÄÆô¶¯Ê±¼ä¡£
./main -c²é¿´cpuÀàÐͺÍkernel°æ±¾¡£
×÷Õߣºbluecloudmatrix