Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 770
Van Coding Avatar asked Jun 22 '26 13:06

Van Coding


1 Answers

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.

like image 170
MrZebra Avatar answered Jun 24 '26 05:06

MrZebra