3

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?

10
  • @FelicePollano Yes, I know. But I ask from a architectural point of view, where things can run on top of each other ;) Commented Apr 28, 2014 at 10:33
  • You might like the wikipedia article on protection ring. Commented Apr 28, 2014 at 10:34
  • The compiled program contains machine language directly run by the cpu. Before running a program, the kernel puts the cpu into a state where certain types of instructions (like the stuff that maps physical memory to virtual memory) from running. It then jumps to the program an lets it run. Commented Apr 28, 2014 at 10:35
  • Good question, but let me just say that a comprehensive introductory text book will contain the answer, well explained. The classic being the Tanenbaum. Also, it’s unorthodox to speak of compiled languages as being compiled “to an interpreted language” (although it’s true that the machine instructions are ultimately interpreted by the hardware). Commented Apr 28, 2014 at 10:35
  • It's a grey area. MSVC has, or had, an option to generate interpretative code. I'm not aware there's anything in the ISO standards that prohibits or prescribes either strategy. However certainly practically all C++ implementations generate code that execute on the hardware. Commented Apr 28, 2014 at 10:38

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

X86 has 4 levels, called rings. The kernel and portions of some device drivers run at the highest level, called ring 0. Applications generally run at the lowest level, called ring 3.
The PDP-11 had seven in the 1970s.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.