Linux驱动层调用应用层程序--call_usermodehelper()
2017-07-31 17:54
579 查看
Linux驱动层调用应用层程序–call_usermodehelper()
在驱动层想要调用用户空间程序主要还是通过call_usermodehelper()这一函数,在这里记录一下;#include<linux/init.h> #include<linux/module.h> #include<linux/moduleparam.h> //#include<linux/config.h> #include<linux/kernel.h>/*printk()*/ #include<linux/sched.h> MODULE_LICENSE("GPL"); static __init int testDriver1_init(void){ int result=0; char cmdPath[]="/bin/bash"; char* cmdArgv[]={cmdPath, "-c", "/bin/ls >> /tmp/list", NULL}; char* cmdEnvp[]={"HOME=/", "PATH=/sbin:/bin:/usr/bin", NULL}; result=call_usermodehelper(cmdPath,cmdArgv,cmdEnvp,UMH_WAIT_PROC); printk(KERN_DEBUG"testDriver1 _init exec! The result of call_usermodehelper is %d\n",result); //printk(KERN_DEBUG"testDriver1_initexec!Theprocess is \"%s\",pidis %d ,sys_getpid is %d \n",current->comm,current->pid); printk(KERN_DEBUG"testDriver1 _init exec! The process is \"%s\",pid is %d\n",current->comm,current->pid); return result; } static __exit void testDriver1_exit(void){ int result=0; char cmdPath[]="/bin/bash"; char* cmdArgv[]={cmdPath, "-c", "/bin/ls >> /tmp/list", NULL}; char* cmdEnvp[]={"HOME=/", "PATH=/sbin:/bin:/usr/bin",NULL}; result=call_usermodehelper(cmdPath,cmdArgv,cmdEnvp,UMH_WAIT_PROC); printk(KERN_DEBUG"testDriver1 _exit exec! The result of call_usermodehelper is %d\n",result); printk(KERN_DEBUG"testDriver1 _exit exec! The process is \"%s\",pid is %d \n",current->comm,current->pid); } module_init(testDriver1_init); module_exit(testDriver1_exit);
对应的Makefile文件
obj-m := testDriver.o KERNEL_DIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) all: make -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules clean: rm *.o *.ko
简单记录,以防后面需要。。。
相关文章推荐
- Linux call_usermodehelper()
- 使用call_usermodehelper在Linux内核中直接运行用户空间程序
- 使用call_usermodehelper在Linux内核中直接运行用户空间程序
- 使用call_usermodehelper在Linux内核中直接运行用户空间程序
- 使用call_usermodehelper在Linux内核中直接运行用户空间程序(转)
- 使用call_usermodehelper在Linux内核中直接运行用户空间程序
- 使用call_usermodehelper在Linux内核中直接运行用户空间程序
- 使用call_usermodehelper在Linux内核中直接运行用户空间程序
- 通过call_usermodehelper()在内核态执行用户程序【转】
- 使用call_usermodehelper在Linux内核中直接运行用户空间程序
- 使用call_usermodehelper在Linux内核中直接运行用户空间程序
- 疑问:Linux中同一个头文件,可否既被驱动代码调用、又被应用代码调用?
- Linux学习:应用层open调用驱动层open过程
- android从应用到驱动之—camera(1)---程序调用流程
- android从应用到驱动之—camera(1)---程序调用流程
- 关于linux驱动(应用)程序头文件使用
- android从应用到驱动之—camera(1)---程序调用流程
- android从应用到驱动之—camera(1)---程序调用流程
- android从应用到驱动之—camera(1)---程序调用流程
- linux应用层下用C调用音频驱动