Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2000518
  • 博文数量: 369
  • 博客积分: 10093
  • 博客等级: 上将
  • 技术积分: 4271
  • 用 户 组: 普通用户
  • 注册时间: 2005-03-21 00:59
文章分类

全部博文(369)

文章存档

2013年(1)

2011年(2)

2010年(10)

2009年(16)

2008年(33)

2007年(146)

2006年(160)

2005年(1)

分类: LINUX

2006-08-10 10:32:51

用户空间程序可以通过系统调用来完成一些需要较高权限才能执行的任务,反过来,内核空间的进程也可以通过调用一些用户空间的程序来完成一些功能,虽然这样做并不是很好。事实上的动态内核模块载入技术就是用这种方法实现的。
示例代码:

#include
#include
#include
#include

static int __init test_init(void)
{
        char *argv[] = {
                "/bin/sh",
                "-c",
                "uname > /tmp/uname",
                NULL};
        char *env[] = {
                "ROOT=/",
                "TERM=linux",
                "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
                NULL};
        int ret;

        printk("Begin the program!\n");
        ret = call_usermodehelper_keys(argv[0], argv, env, NULL, 1);
        printk("End with %d\n", ret);

        return 0;
}

static void __exit test_exit(void)
{
}

module_init(test_init);
module_exit(test_exit);
注意:
必须要谨慎小心,留意安全方面的问题!

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