Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute shell command in kernel programming?

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.

like image 625
user2122972 Avatar asked Mar 28 '13 07:03

user2122972


People also ask

Which command is used to execute the shell script?

3. Execute Shell Script Using . ./ (dot space dot slash) While executing the shell script using “dot space dot slash”, as shown below, it will execute the script in the current shell without forking a sub shell.


1 Answers

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);
like image 119
Ilya Matveychikov Avatar answered Oct 12 '22 23:10

Ilya Matveychikov