简体   繁体   English

C / C ++程序是在CPU上还是在内核上运行?

[英]Does a C/C++ program run the CPU or on the Kernel?

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. 例如,必须先将C / C ++编译为机器语言,然后才能执行。

And here comes my question: Who does actually run a compiled C/C++ Windows/Linux program? 这是我的问题:谁真正运行已编译的C / C ++ Windows / Linux程序? Is it interpreded by the CPU directly, or does the OS Kernel execute it and pass the commands to the CPU? 它是由CPU直接解释的,还是OS内核执行它并将命令传递给CPU?

And if the CPU executes it directly, how can the Windows Kernel then deny some calls? 如果CPU直接执行它,那么Windows内核又如何拒绝某些调用呢? Otherwise, does it mean that the Kernel understands machine language as well, or do non-kernel C/C++ programs not compile to machine language? 否则,这是否意味着内核也理解机器语言,还是非内核C / C ++程序不能编译为机器语言?

The program runs on the CPU. 该程序在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. CPU具有不同的特权级别,因此所谓的“特权指令”只能由内核执行-这就是操作系统强制执行安全性的方式。

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

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