错误:'struct task_struct'没有名为'it_virt_value'的成员

时间:2015-12-17 21:30:10

标签: linux kernel

我正在尝试在Linux ubuntu-studio中创建一个具有以下功能的系统调用:

为虚拟内存带来更大的进程以及它占用的字节数。

下面是系统调用的实现代码:

#include <linux/module.h>
#include <linux/printk.h>
#include <linux/sched.h>

struct pid_size{
    int pid;
    unsigned long size;
};


struct pid_size pid maiorMemoriaVirtual(void)
{
    struct task_struct *task;
    struct task_struct *maior = NULL;

    for_each_process(task)
    {
        if(maior == NULL)
            maior = task; 
        else if(task->it_virt_value > maior->it_virt_value)
            maior = task;
    }

    struct pid_size retorno;
    retorno.pid = maior->pid;
    retorno.size = maior->it_virt_value;

    return retorno;
}

编译尝试编译内核时出现以下错误:

kernel/maiorMemoriaVirtual.c: In function ‘sys_maiorMemoriaVirtual’:
kernel/maiorMemoriaVirtual.c:19:21: error: ‘struct task_struct’ has no member named ‘it_virt_value’
         else if(task->it_virt_value > maior->it_virt_value)
                     ^
kernel/maiorMemoriaVirtual.c:19:44: error: ‘struct task_struct’ has no member named ‘it_virt_value’
         else if(task->it_virt_value > maior->it_virt_value)
                                            ^
kernel/maiorMemoriaVirtual.c:23:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     struct pid_size retorno;
     ^
kernel/maiorMemoriaVirtual.c:25:25: error: ‘struct task_struct’ has no member named ‘it_virt_value’
     retorno.size = maior->it_virt_value;
                         ^
make[1]: ** [kernel/maiorMemoriaVirtual.o] Erro 1

1 个答案:

答案 0 :(得分:1)

我在完成作业时遇到了类似的问题,我意识到对“任务结构”的定义做了很多改动。结构体。

我的猜测是你正在寻找累积的虚拟内存使用量。您可能会发现此链接很有用。 Accumulated Virtual Memory usage

Link to the task_struct definition in kernel 2.6.36