I know that we can call user space from Kernel Module, using the call_usermodehelper function.

Prototype call_usermodehelper (const char * path, char ** argv, char ** envp, int wait)


const char * path is a path to usermode executable

char ** argv is arg vector for process

char ** envp environment for process

int wait is some sort of enumeration

When I try to run my python script, in this way

    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/fs.h>
    #include <linux/uaccess.h>
    #include <linux/kmod.h>

static int __init mpc_init(void) {

char *argv[]= {"/bin/bash","-c","/dir1/dir2/file.py",NULL};
static char *envp[]={
               "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/    local/games:/usr/games",NULL};

printk(KERN_INFO "yes");

return call_usermodehelper(argv[0],argv,envp,UMH_WAIT_EXEC); 


static void __exit mpc_exit(void) {       
    printk(KERN_INFO "no");


I can see that a process can be created, but It gets killed in short time.

Maybe my module needs allocated memory?

closed as off-topic by Rui F Ribeiro, Jeff Schaller May 27 at 20:02

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Try running /bin/bash -c /dir1/dir2/file.py directly from the command line, and you will see why it fails. You are apparently trying to run python code as a bash script. – Johan Myréen May 27 at 19:02
  • It work from command line. Maybe, the reason is that my python file use a lot of modules, and I need to load them with a kernel module? – Michele Lo Presti May 28 at 17:17
  • What do you need bash for? Why don't you start the Python script directly? – Johan Myréen May 28 at 17:57
  • I also ran it directly from command line, but with the same result – Michele Lo Presti May 28 at 19:28