Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
C++
#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);
Posted
Updated 27-Dec-11 7:36am
v2
Comments
Wendelius 27-Dec-11 13:36pm    
Pre tags added

1 solution

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
 
Share this answer
 
Comments
merturk 27-Dec-11 13:42pm    
I make it, debug and work to run but it doesn't. there is no compilation error I said, did you read?. It doesn't work properly and I don't know the reason.
Sergey Alexandrovich Kryukov 27-Dec-11 14:13pm    
Congratulation! You probably down-voted the answer out of your extreme ignorance.

If I say "run under debugger", it -- just the opposite -- assumes your compilation was successful. Did you read it?
No run time would be possible if you had one single compilation error -- isn't this obvious?

Your successful compilation does not mean any useful functionality, don't you understand it?

Now, "I debug it" does not mean you debugged anything. It looks like you did not see where the problem is. If you did, you would point it out. My opinion is: you are not ready yet to get help on the topic, unless someone decides to get in the code and debug it for you, but I don't think it can really help you.

Not to worry -- you can learn all that. All you need is your willing to understand...
--SA
merturk 27-Dec-11 15:08pm    
if I understand I can solve it, okey. that is a question if you don't want don't write anything,do you thing to be coder of the month, you should write everywhere. It is wrong man. if you don't know or don't want to reply please Don't write anything to my question...
Sergey Alexandrovich Kryukov 27-Dec-11 18:06pm    
Why do you think so? You just write it out of your irritation. And please don't call me a coder if you don't know. I write only what I thing is important. What you need the most is understanding the method of work and some accuracy in asking questions, not particular technical detail. I look at your first line "int *arry[1000]", it's enough for me to see that is't pretty far from real programming. But it's OK, you can learn it. Even though I readily listen to advice by any people, mature or very beginners, let me choose by myself on what topic to write an on what not.

Best,
--SA
theanil 28-Dec-11 12:55pm    
Good observation SA, about array notification.
my 5 for your observation

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900