Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1069668
  • 博文数量: 252
  • 博客积分: 4561
  • 博客等级: 上校
  • 技术积分: 2833
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-15 08:23
文章分类

全部博文(252)

文章存档

2015年(2)

2014年(1)

2013年(1)

2012年(16)

2011年(42)

2010年(67)

2009年(87)

2008年(36)

分类: LINUX

2009-11-30 15:31:16

#include <linux/module.h>
#include <linux/init.h>
#include <asm/atomic.h>
#include <linux/kthread.h>
#include <linux/delay.h>

#define err(msg) printk(KERN_ALERT "%s\n", msg)

static struct task_struct *task;

static int kthread_func(void *data)
{
        while (1) {

                if (kthread_should_stop())
                        break;

                printk(KERN_ALERT "kthread_func.\n");
                msleep(1000);
        }

        return 0;
}

static int maininit(void)
{
        if ((task = kthread_create(kthread_func, NULL, "tmp%d", 0)) == NULL) {
                err("kthread_create");
                goto err;
        }

        wake_up_process(task);

        return 0;
err:
        return -1;
}

static void mainexit(void)
{
        kthread_stop(task);
}

module_init(maininit);
module_exit(mainexit);

MODULE_LICENSE("GPL");


阅读(2265) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~