本文介绍了函数声明不是C中的原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习为linux编写内核模块作为初学者。我想做的是使用DFS算法将每个任务及其子进程写入内核日志。但是当我使用 Makefile 编译代码时,它显示以上错误:

I'm learning to write kernel modules for linux as a beginner. What I'm trying to do is to write every task and its child process into the kernel log using DFS algorithm. But when I compile the code using Makefile, it shows the above error:

function declaration isn’t a prototype [-Werror=strict-prototypes]
struct task_struct *current;

它指出了 task_struct 函数DFS。
这是我的代码:

It points out the task_struct keyword at the function DFS.Here's my code:

# include <linux/init.h>
# include <linux/kernel.h>
# include <linux/module.h>
# include <linux/sched.h>
# include <linux/list.h>

void DFS (struct task_struct *task)
{
    struct task_struct *current;
    struct list_head *list;

    list_for_each (list, &task->children)
    {
        current = list_entry(list, struct task_struct, sibling);
        printk(KERN_INFO "%d\t%d\t%s \n", (int)current->state, current->pid, current->comm);

        if (current != NULL)
        {
            DFS(current);
        }
    }
}

int DFS_init(void)
{
    printk(KERN_INFO "Loading the Second Module...\n");

    printk(KERN_INFO "State\tPID\tName\n");

    DFS(&init_task);

    return 0;
}

void DFS_exit(void)
{
    printk(KERN_INFO "Removing the Second Module...\n");
}

任何人都知道如何解决这个问题

Anyone knows how to fix this ??

编辑

我发现错误。看起来像C不允许创建一个变量 * current 。我改成了另一个名字,它编译!!!

I found the error. Seems like C doesn't allows to make a variable called *current. I changed it to another name and, it compiled !!!

推荐答案

Kernal有一个内置的变量c $ c> current ,它指向当前正在执行进程的用户。如所述,

Kernal has an inbuilt variable (or pointer) called current which is pointing to users currently executing process. As This book states,

使用 current 作为变量名将给出编译时错误!

So, using current as a variable name will gives a compile-time error !!!

这篇关于函数声明不是C中的原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 16:05
查看更多