简体   繁体   English

内核编程

[英]kernel programming

除了shell和系统调用之外,还有其他使用内核执行程序的方法吗?

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. 在过去,通常只有一种方法可以在Unix及其派生程序上执行程序,那就是通过exec()系统调用。 The very first (kernel) process was created by the boot loader; 第一个(内核)进程是由引导加载程序创建的; all subsequent processes were created by fork() and exec() . 所有后续进程都是由fork()exec() Of course, fork() only created a copy of the original program; 当然, fork()仅创建原始程序的副本; 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. 正是exec()系统调用(以C源代码的多种形式之一,但最终等同于execve()完成了用新映像替换当前进程的驴工作。

These days, there are mechanisms like posix_spawn() which might, or might not, use a separate system call to achieve roughly the same mechanism. 如今,有诸如posix_spawn()类的机制可能会或可能不会使用单独的系统调用来实现大致相同的机制。

A lot of kernels has support for adding kernel modules or drivers at run time. 许多内核都支持在运行时添加kernel modulesdrivers 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. 根据驱动程序的实现,您将必须具有某种触发机制才能在内核空间中执行代码。

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) 内核是事件驱动的,只有系统调用才能触发其模块的执行(除了某些系统事件,例如收到的网络数据包)

是的,您可以使用源程序编译内核,但这并不是最明智的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM