在linux kernel层调用用户层的方法

来源:互联网 发布:linux 解压gz文件脚本 编辑:程序博客网 时间:2024/06/06 02:29

首先调用 call_usermodehelper_setup 来创建已初始化的 subprocess_info 结构。

然后使用 call_usermodehelper_exec 函数执行相关的命令,,这里执行 rm /home/xxf/test 命令

static int kernel_userspace( void ){  struct subprocess_info *sub_info;  char *argv[] = { "/bin/rm", "/home/xxf/test", NULL };  static char *envp[] = {        "HOME=/",        "TERM=linux",        "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL };  sub_info = call_usermodehelper_setup( argv[0], argv, envp, GFP_ATOMIC );  if (sub_info == NULL) return -ENOMEM;  return call_usermodehelper_exec( sub_info, UMH_WAIT_PROC );}

From:https://www.ibm.com/developerworks/cn/linux/l-user-space-apps/

阅读全文
0 0
原创粉丝点击