Linux 内核线程启动以及内核调用应用层程序

#include //内核线程头文件
 

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)

唤醒线程函数:wake_up_progress(test_task)

你可能感兴趣的:(linux)