#include <linux/kthread.h> //内核线程头文件
static task_struct *test_task;
test_task = kthread_run(thread_function, NULL, "test_thread_name");
if(IS_ERR(test_task))
{
pr_err("test_thread_name create fail\n");
}
static int thread_function(void *arg)
{
char *envp[3];
char *argv[3];
int ret= 0;
argv[0] = "/bin/sh";
argv[1] = "/etc/test_shell.sh";
argv[2] = NULL;
envp[0] = "HOME=/";
envp[1] = "PATH=/sbin:/bin:/usr/bin";
envp[2] = NULL;
ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
pr_info("ret is %d\n", ret);
return 0;
}
其他:
线程停止函数:kthread_stop(test_task)文章来源:https://www.toymoban.com/news/detail-659219.html
唤醒线程函数:wake_up_progress(test_task)文章来源地址https://www.toymoban.com/news/detail-659219.html
到了这里,关于Linux 内核线程启动以及内核调用应用层程序的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!