开发者

kernel programming

开发者 https://www.devze.com 2023-02-02 06:03 出处:网络
Is the开发者_运维技巧re any other way to execute a program using kernel, other than shell and system calls?It always used to be the case that there was really only one way to execute a program on Unix

Is the开发者_运维技巧re any other way to execute a program using kernel, other than shell and system calls?


It always used to be the case that there was really only one way to execute a program on Unix and its derivatives, and that was via the exec() system calls. The very first (kernel) process was created by the boot loader; all subsequent processes were created by fork() and exec(). Of course, fork() only created a copy of the original program; it was the exec() system call - in one of a number of forms in the C source code, but eventually equivalent to execve() - that did the donkey work of replacing the current process with a new image.

These days, there are mechanisms like posix_spawn() which might, or might not, use a separate system call to achieve roughly the same mechanism.


A lot of kernels has support for adding kernel modules or drivers at run time. If you want to execute some code from kernel space (probably because you need higher privileges), you can write a kernel module/driver of your own and load it to execute your code. However, inserting a driver only doesn't ensure that your code will be executed. Based on your driver implementation, you will have to have some triggering mechanism for executing your code in kernel space.


yeah, you can compile your kernel with your program sourced in it, but it won't be the smartest thing to do.


Every program is internally executed by Kernel. If you are looking for running kernel module, you have to use the system calls to reach that module and perform some work for you in Kernel mode. Kernel is event driven and only system calls trigger execution of its modules (apart from some system events like network packet received)

0

精彩评论

暂无评论...
验证码 换一张
取 消