开发者

sys/wait.h and sys/kthread.h do not compile together

I am compiling a kernel module in linux related to creating kthreads to achieve parallelism but I am stuck at compiling issues.

Here is my code:

#include <linux/init.h>
#include <linux/errno.h>
#include <asm/byteorder.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/types.h>
#include <sys/wait.h>

void threadfn1()
{
 int j;
 for( j = 0; j < 1000000; j++ )
  printk(KERN_INFO "I AM THREAD 1 %d\n",j); 
}

void threadfn2()
{
 int j;
 for( j = 0; j < 1000000; j++ )
  printk(KERN_INFO "I AM THREAD 2 %d\n",j);

}

static int __init abc_init(void)
{
 struct task_struct *t1 = kthread_run(threadfn1, NULL, "thread1");
 struct task_struct *t2 = kthread_run(threadfn2, NULL, "thread2");

 printk(KERN_INFO "HELLO WORLD\n");
 waitpid(-1,NULL,0); // whatever the parameters of waitpid() are
}

static void __exit abc_fini(void)
{
 printk(KERN_INFO "BYE WORLD\n");
}

module_init(abc_init);
module_exit(abc_fini);

The problem with my code is that when i compile my kernel module with make, sys/wait.h gives compiling errors like "redefinition of some strcut xyz" any many more errors, when linux/module.h and linux/kthread.h are also included. As soon as i comment out these two files, the module compiles well but gives a linking error that "waitpid" is undefined.

Why doesnt sys/wait.h compile well with linux/kthread.开发者_高级运维h and linux/module.h? Has anyone encountered this problem before?

Any help would be appreciated.


It is incorrect to include userspace headers, like sys/wait.h, in kernel code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜