实验环境:
CentOS Linux release 7.4.1708,3.10.0-693.el7.x86_64
参考:
内核 API,第 1 部分:从内核调用用户空间应用程序
https://www.ibm.com/developerworks/cn/linux/l-user-space-apps/index.html
demo:
#include <linux/module.h>
static int umh_test( void )
{
struct subprocess_info *sub_info;
char *argv[] = { "/usr/bin/touch", "/abc.txt", 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_KERNEL , NULL, NULL, NULL);
if (sub_info == NULL) {
printk("call_usermodehelper_setup error");
return -ENOMEM;
}
return call_usermodehelper_exec( sub_info, UMH_WAIT_PROC );
}
s