zoukankan      html  css  js  c++  java
  • kernel/info.c

    /*
     * linux/kernel/info.c
     *
     * Copyright (C) 1992 Darren Senn
     */

    /* This implements the sysinfo() system call */

    #include <asm/segment.h>

    #include <linux/sched.h>
    #include <linux/string.h>
    #include <linux/unistd.h>
    #include <linux/types.h>
    #include <linux/mm.h>

    //系统信息
    asmlinkage int sys_sysinfo(struct sysinfo *info)
    {
        int error;
        struct sysinfo val;
        struct task_struct **p;

        //校验
        error = verify_area(VERIFY_WRITE, info, sizeof(struct sysinfo));
        if (error)
            return error;
        //初始化变量val
        memset((char *)&val, 0, sizeof(struct sysinfo));

        //系统信息初始化
        val.uptime = jiffies / HZ;

        val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
        val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
        val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);

        //遍历任务进程,统计任务进程数量
        for (p = &LAST_TASK; p > &FIRST_TASK; p--)
            if (*p) val.procs++;

        si_meminfo(&val);
        si_swapinfo(&val);

        //将系统信息输出到用户空间
        memcpy_tofs(info, &val, sizeof(struct sysinfo));
        return 0;
    }

  • 相关阅读:
    [LeetCode] 617. Merge Two Binary Trees
    [LeetCode] 738. Monotone Increasing Digits
    289. Game of Life
    305. Number of Islands II
    288. Unique Word Abbreviation
    271. Encode and Decode Strings
    393. UTF-8 Validation
    317. Shortest Distance from All Buildings
    286. Walls and Gates
    296. Best Meeting Point
  • 原文地址:https://www.cnblogs.com/xiaofengwei/p/3774126.html
Copyright © 2011-2022 走看看