Linux kernel vs Windows kernel

Linux kernel vs Windows kernel

Liang Xu Linux  Today

The following article comes from Kobayashi coding, the author Kobayashi coding

Kobayashi coding

Kobayashi coding

Sometimes illustrated technology, sometimes filmed cat videos, sometimes talked about chores

 

image

 

Windows and Linux can be said to be two of our more common operating systems.

Windows has basically occupied the market in the computer age and has achieved great commercial success, but it is not open source, so if you want to get access to the source code, you have to join the Windows development team.

The operating system used by the server is basically Linux, and the kernel source code is also open source. Anyone can download and add their own changes or functions. The biggest charm of Linux is that there are so many technical experts around the world for it. Contribute code.

These two operating systems have their own advantages and disadvantages.

The core of the operating system is the kernel. This time we will take a look. What is the difference between the Linux kernel and the Windows kernel?


Kernel

What is the kernel?

The computer is composed of various external hardware devices, such as memory, cpu, hard disk, etc. If each application has to interface with these hardware devices with a communication protocol, it will be too tiring.

Therefore, the middleman is the responsibility of the kernel , and the kernel is used as the bridge between the application and the hardware device . The application only needs to care about the interaction with the kernel, not the details of the hardware.

image

Kernel

What are the capabilities of the kernel?

In modern operating systems, the kernel generally provides four basic capabilities:

  • Manage processes and threads, decide which process or thread uses the CPU, that is, the ability of process scheduling;

  • Manage memory, determine the allocation and recovery of memory, that is, the ability of memory management;

  • Manage hardware devices and provide communication capabilities between processes and hardware devices, that is, hardware communication capabilities;

  • Provide system calls. If an application program wants to run a service with a higher authority, then a system call is required, which is the interface between the user program and the operating system.

How does the kernel work?

The kernel has a very high authority, which can control hardware such as cpu, memory, hard disk, and the application program has very little authority. Therefore, most operating systems divide the memory into two areas:

  • Kernel space, this memory space can only be accessed by kernel programs;

  • User space, this memory space is dedicated to applications;

User space code can only access a local memory space, while kernel space code can access all memory spaces.

Therefore, when a program uses user space, we often say that the program executes in user mode , and when the program uses kernel space, the program executes in kernel mode .

If the application needs to enter the kernel space, it needs to pass the "system call", let's take a look at the process of the system call:

image

The kernel program is executed in the kernel mode, and the user program is executed in the user mode. When the application program uses the system call, an interrupt is generated. After an interrupt occurs, the CPU will interrupt the user program currently being executed, and then jump to the interrupt handler, that is, start executing the kernel program. After the kernel finishes processing, it actively triggers an interrupt, returns the CPU execution authority to the user program, and returns to the user mode to continue working.


Linux design

The first ancestor of Linux came from a Finnish guy named Linus Torvalds, who wrote the first version of the Linux operating system in C language in 1991, when he was 22 years old.

After completing the first version of Linux, Linux Torvalds released the source code of the Linux kernel on the Internet, which everyone can download and use for free.

The concept of Linux kernel design mainly has these points:

  • MutiTask , multitasking

  • SMP , symmetric multiprocessing

  • ELF , executable file link format

  • Monolithic Kernel , macro kernel

MutiTask

MutiTask means multitasking , which means that Linux is a multitasking operating system.

Multitasking means that multiple tasks can be executed at the same time. Here, "simultaneous" can be concurrent or parallel:

  • For a single-core CPU, each task can be executed for a short period of time, and another task is switched when the time is up. From a macro perspective, multiple tasks are executed within a period of time, which is called concurrency.

  • For multi-core CPUs, multiple tasks can be executed by CPUs with different cores at the same time, which is called parallelism.

Junior High

SMP means symmetric multiprocessing , which means that the status of each CPU is equal, and the usage rights of resources are also the same. Multiple CPUs share the same memory, and each CPU can access complete memory and hardware resources.

This feature determines that the Linux operating system will not have a single CPU service application or kernel program, but each program can be assigned to any CPU to be executed.

ELF

ELF means executable file link format , which is the storage format of executable files in the Linux operating system. You can see its structure from the figure below:

image

ELF file format

ELF divides the file into sections. Each section has its own function. I won’t elaborate on the specific function of each section here. Those who are interested can read the "Programmer’s Self-cultivation-Link Loading and Library" this book.

In addition, the ELF file has two indexes. The Program header table records the sections required by "runtime", and the Section header table records the "first address of each section" in the binary file.

How is the ELF file generated?

The code we write is first compiled into assembly code through the "compiler", then into object code, which is the object file, through the "assembler", and finally multiple object files and various function libraries called by the "linker" Link together to form an executable file, which is an ELF file.

How is the ELF file executed?

When the ELF file is executed, the ELF file is loaded into the memory through the "loader", the CPU reads the instructions and data in the memory, and the program is executed.

Monolithic Kernel

Monolithic Kernel means macro kernel . The Linux kernel architecture is a macro kernel, which means that the Linux kernel is a complete executable program and has the highest authority.

The feature of the macro kernel is that all modules of the system kernel, such as process scheduling, memory management, file system, device drivers, etc., are all running in the kernel mode.

However, Linux also implements the function of dynamically loading kernel modules. For example, most device drivers exist in the form of loadable modules, decoupling with other kernel modules, making driver development and driver loading more convenient and flexible.

image

Operating system structure of macro kernel, micro kernel, and mixed kernel respectively

The opposite of the macro kernel is the micro kernel . The kernel of the micro kernel architecture retains only the most basic capabilities, such as process scheduling, virtual machine memory, interrupts, etc., and places some applications in the user space, such as drivers, file systems, and so on. In this way, services and services are isolated, and a single service failure or complete attack will not cause the entire operating system to hang, which improves the stability and reliability of the operating system. 

The micro-kernel kernel has fewer functions and high portability. Compared with the macro kernel, the disadvantage is that because the driver is not in the kernel, and the driver usually calls the underlying capabilities frequently, the interaction between the driver and the hardware device needs to be frequent Switch to kernel mode, which will bring performance loss. The kernel architecture of Huawei's Hongmeng operating system is the microkernel.

There is also a kind of kernel called a hybrid kernel . Its architecture is a bit like a micro kernel. There will be a minimum version of the kernel in the kernel. Then other modules will be built on this basis, and then the implementation will be similar to the macro kernel. The entire kernel is made into a complete program, and most of the services are in the kernel, which is like a macro kernel wrapping a micro kernel.


Windows design

Nowadays, the kernel used by Windows 7 and Windows 10 is called Windows NT, and the full name of NT is New Technology.

The following figure is a picture of the structure of Windows NT:

image

The structure of Windows NT

Windows, like Linux, also supports MutiTask and SMP, but the difference is that the kernel design of Windows is a hybrid kernel . In the figure above, you can see that there is a  MicroKernel  module in the kernel. This is the smallest version of the kernel, and the entire kernel is implemented. It is a complete program with many modules.

The format of the executable file of Windows is also different from that of Linux, so the executable files of these two systems cannot be run on each other.

Windows executable file format called PE, called portable executable file , usually extension .exe, .dll, .sysand so on.

The structure of PE, as you can see from the figure below, is a bit similar to the structure of ELF.

image

PE file structure


to sum up

There are generally three types of core architectures:

  • Macro kernel contains multiple modules, and the entire kernel is like a complete program;

  • Microkernel, there is a minimum version of the kernel, some modules and services are managed by the user mode;

  • Hybrid kernel is a combination of macro kernel and micro kernel. The concept of micro kernel is abstracted from the kernel, that is, there will be a small kernel in the kernel, and other modules are built on this basis. The entire kernel is a complete program;

The kernel design of Linux adopts the macro kernel, and the kernel design of Windows adopts the hybrid kernel.

The executable file formats of these two operating systems are different. The Linux executable file format is called ELF, and the Windows executable file format is called PE.

Guess you like

Origin blog.csdn.net/wzlsunice88/article/details/114065683