How to execute shell command in kernel programming?

user2122972 picture user2122972 · Mar 28, 2013 · Viewed 11.1k times · Source

I want to use system() function of stdlib.h in my c code. I am actually working on kernel programming.

Whenever i want to use system() in it, it gives error to stdlib.h saying no such file found.

Answer

Ilya Matveychikov picture Ilya Matveychikov · Mar 28, 2013

It's simple!

#include <linux/kmod.h>

char * envp[] = { "HOME=/", NULL };
char * argv[] = { "/bin/ls", NULL };

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