问题
I'm programming for quite some years now, but there's one thing that I never understood exactly:
There are 2 types of programming languages. Compiled ones and interpreted ones, while compiled ones first need to be to compiled to a interpreted language, before they can be executed.
For example, C/C++ needs to be compiled to machine language first, before it can be executed.
And here comes my question: Who does actually run a compiled C/C++ Windows/Linux program? Is it interpreded by the CPU directly, or does the OS Kernel execute it and pass the commands to the CPU?
And if the CPU executes it directly, how can the Windows Kernel then deny some calls? Otherwise, does it mean that the Kernel understands machine language as well, or do non-kernel C/C++ programs not compile to machine language?
回答1:
The program runs on the CPU. The CPU has different levels of privilege, so called "privileged instructions" may only be executed by the kernel - that's how security is enforced by the operating system.
来源:https://stackoverflow.com/questions/23338684/does-a-c-c-program-run-the-cpu-or-on-the-kernel