linux内核模块处理状态 [英] linux kernel module processes states

查看:98
本文介绍了linux内核模块处理状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里我要编写一个内核模块,该模块打印内核中所有进程的状态,但是我无法运行它,没有编译错误,这是怎么回事?

here I want to write a kernel module that prints the states of all processes at the kernel but I can''t run it, there is no compilation error, what is the wrong here?

#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h>   /* Needed for KERN_INFO */
#include <linux/init.h>     /* Needed for the macros */
#include <linux/moduleparam.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/unistd.h>

int *arry[1000];
int i=0;
int level=0;

static char *md="-n";

module_param(md,charp,0000);
MODULE_PARM_DESC(md,"parametre");

void recursion(struct task_struct *t){
    level++;
    struct task_struct *t2;
    bool isFound=false;
    int k,l;
    for_each_process(t2){
        if(t2->parent==t){
            for(k=0;k<1000;k++){
                if(!strcmp(arry[k],t2->state)){
                    isFound=true;
                    break;
                }
            }
            if(isFound==false){
                for(l=0;l<level;l++){
                    printk("    ");
                }
                printk(KERN_INFO "%s",t2->state);
                if(!strcmp(md,"-p"))
                    printk(KERN_INFO "(%d)\n",t2->pid);
                else
                    printk("\n");
                arry[i]=t2->state;
                i++;
                recursion(t2);
            }
            isFound=false;
        }
    }
    level--;
}

static int __init project4_init(void)
{
struct task_struct *t;

    int j;
    bool isFound=false;
    for(j=0;j<1000;j++){
        arry[j]="*******";
    }

    for_each_process(t){
        for(j=0;j<1000;j++){
            if(!strcmp(arry[j],t->state)){
                isFound=true;
                break;
            }
        }
        if(isFound==false){
            arry[i]=t->state;
            i++;
            printk(KERN_INFO "%ld",t->state);
                if(!strcmp(md,"-p"))
                    printk(KERN_INFO "(%d)\n",t->pid);
                else
                    printk("\n");
            recursion(t);
        }
        isFound=false;
    }

    return 0;
}
static void __exit project4_exit(void)
{
    printk(KERN_INFO "Goodbye, world 2\n");
}

module_init(project4_init);

module_exit(project4_exit);

推荐答案

现在,在调试器上运行它.从您的问题来看,我认为您还没有这样做,否则您会询问特定的代码行.如果仍然不能解决您的问题,则作为另一个问题,这次更具体.

—SA
Now, run it under debugger. From your question, I would assume you haven''t done it, otherwise you would ask about particular lines of code. If it still does not resolve your problem, as another question, this time more specific.

—SA


这篇关于linux内核模块处理状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆