关闭

Linux操作系统内核实习(一)

标签: linuxsystemredhat360cdisk
964人阅读 评论(0) 收藏 举报
分类:

Exercise One

Part A

1. What is the cpu type and model?

/proc/cpuinfo

2. What version of the linux kernel is being used?

/proc/version

3. How long has it been since the system was last booted?

/proc/uptime

4. How much of the total cpu time has been spent executing in user model? System model? Idle?

/proc/stat

5. How much memory is configured into it?

/proc/meminfo

6. How many disk read/write requests have been made?
How many context switches has the kernel performed?
How many processes have been created since the system was booted?

/proc/stat

Part B: Programming

#include <stdio.h>
#define MAX_CHAR 80

int main(int argc, char* argc[])
{
    FILE* filp;
    char c[80];
    char* ctemp;
    int err;

    filp = fopen("/proc/cpuinfo", "r");
    if (filp < 0)
        goto fail;
    printf("The cpu type and model:/n");
    while ((ctemp = fgets(c, MAX_CHAR, filp)) > 0)
    {
        if (strstr(c, "vendor_id") || (strstr(c, "model") && strstr(c, "name")) || (strstr(c, "cpu") && strstr(c, "MHz")))
             printf(c);
    }
    if (ctemp < 0)
        goto fail;

    filp = fopen("/proc/uptime", "r");
    if (filp < 0)
        goto fail;
    if ((ctemp = fgets(c, MAX_CHAR, filp)) >= 0)
    {
        if (sscanf(c, "%d", &err))
            printf("seconds:%d/n", err);
        printf("%d:%d:%d:%d/n", err/(24*3600), err/3600-err(24*3600)*24, err/60-err/3600*60, err%60);
    }

    return 0;
fail:
    return -1;
}

The program above is tested in Redhat 9.0.

chen 2006-5-21

0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:375377次
    • 积分:5319
    • 等级:
    • 排名:第5053名
    • 原创:102篇
    • 转载:76篇
    • 译文:8篇
    • 评论:249条
    博客专栏
    最新评论