首先调用 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/