Executing a shell command in a kernel module

Is it possible to execute a shell command in a kernel module. I know that we can do this in user space C space using the system routine.
I am debugging a kernel module that has a memory leak problem. After executing insmod and rmmod module.ko in an infinite loop, the system exits memory for several minutes with 8G RAM.
It would be useful to know the state of the memory using the free command before and after calling the API responsible for freeing memory so that I can know if the API is working or not.
So I am debugging. Please share if there is any other way to do this.

+5
source share
3 answers

You can use the call_usermodehelper function. See an example of how to use it in LXR # 1 or LXR # 2 .

UPD:

 argv[0] = "/bin/bash"; argv[1] = "-c"; argv[2] = "/usr/bin/free"; argv[3] = NULL; envp[0] = "HOME=/"; envp[1] = "TERM=linux"; envp[2] = "PATH=/sbin:/usr/sbin:/bin:/usr/bin"; envp[3] = NULL; call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC); 
+8
source

You cannot run the shell command in . The code in the kernel module may cause the command to run, but it will work in a normal user process.

free will not help much with kernel memory leaks.
It would be much better to wrap all distributions and free the kernel in your code and save the allocated memory counter.

+6
source

Unable to run shell command from inside the kernel. Instead, you can read the / proc / meminfo file by calling the appropriate procfs API to read the / proc / meminfo file. This virtual file has useful memory statistics about system memory.

+1
source

All Articles