实验环境:
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 );
}
static int __init sample_init(void)
{
printk("usermode-helper start\n");
umh_test();
printk("usermode-h

在CentOS 7.4上进行实验,探讨如何从Linux内核调用用户程序。参考了相关内核API教程,通过示例代码说明在执行如echo到文件的操作时遇到的问题,可能是由于缺少终端和标准输出导致。为避免insmod加载模块时签名错误,需在Makefile中设置CONFIG_MODULE_SIG=n。
最低0.47元/天 解锁文章
138

被折叠的 条评论
为什么被折叠?



