Home System Tutorial LINUX Subvert your understanding of operating systems - an overview of Linux distributions

Subvert your understanding of operating systems - an overview of Linux distributions

Feb 13, 2024 pm 09:15 PM
linux linux tutorial linux system linux command shell script NIC driver embeddedlinux Getting started with linux linux learning

Whether you are a senior programmer or a beginner, whether you are a Windows or macOS user, if you have a certain understanding of computer operating systems, then the name Linux will definitely be familiar to you. However, you may only scratch the surface of the Linux operating system. In fact, there are many Linux distributions, each with unique features and application scenarios. Below, we will introduce you to several common Linux distributions and help you subvert the traditional understanding of operating systems.

In order to enable multiple devices to communicate with each other through the network, and to solve the compatibility issues of various devices in network interconnection, the International Standardization Organization has formulated the open system interconnection reference model (open System Interconnection Reference Model) , which is the OSI network model. This model mainly has 7 layers, namely application layer, presentation layer, session layer, transport layer, network layer, data link layer and physical layer.

Subvert your understanding of operating systems - an overview of Linux distributions
Each layer is responsible for different functions, as follows:

•Application layer is responsible for providing a unified interface to applications;

•The presentation layer is responsible for converting data into a format that is compatible with another system;

•Session layer, responsible for establishing, managing and terminating communication sessions between presentation layer entities;

•Transport layer, responsible for end-to-end data transmission;

•Network layer, responsible for data routing, forwarding, and fragmentation;

•Data link layer, responsible for data framing and error detection, as well as MAC addressing;

•Physical layer, responsible for transmitting data frames in the physical network;

Because the OSI model is too complex, what is proposed is only a conceptual and theoretical layering, and no specific implementation plan is provided. In fact, the four-layer model, which is more common and practical, is the TCP/IP network model. The Linux system implements the network protocol stack according to this network model.

The TCP/IP network model has 4 layers, namely application layer, transport layer, network layer and network interface layer. The functions of each layer are as follows:

•Application layer, responsible for providing users with a set of applications, such as HTTP, DNS, FTP, etc.;

•Transport layer, responsible for end-to-end communication, such as TCP, UDP, etc.;

•Network layer, responsible for encapsulation, fragmentation, routing, and forwarding of network packets, such as IP, ICMP, etc.;

•Network interface layer, responsible for the transmission of network packets in the physical network, such as network packet framing, MAC addressing, error detection, and transmission of network frames through the network card, etc.;

Compared with the OSI network model, the TCP/IP network model is much simpler and easier to remember. The relationship between them is as follows:

Subvert your understanding of operating systems - an overview of Linux distributions
However, the seven-layer and four-layer load balancing we often talk about are described by the OSI network model. Layer seven corresponds to the application layer, and layer four corresponds to the transport layer.

Linux Network Protocol Stack

We can compare our body to the data in the application layer, the base clothes to the TCP header in the transport layer, the coat to the IP header in the network layer, and the hat and shoes to the frame headers in the network interface layer. and the end of the frame.

In the winter season, when we want to go out to play from home, we naturally have to put on base clothes first, then put on a warm jacket, and finally put on a hat and shoes before going out. This process is like when we put on the TCP protocol When the communication network packet is sent out, the application layer data will be encapsulated and processed layer by layer according to the network protocol stack.

You can see from the picture below the encapsulation format of application layer data at each layer.

Subvert your understanding of operating systems - an overview of Linux distributions
in:

•Transport layer adds a TCP header in front of the application data;

•Network layer, adds IP header in front of TCP packet;

•The network interface layer adds a frame header and a frame trailer before and after the IP packet;

These new additions, headers and tails all have their own functions, and are filled in according to a specific protocol format. Each layer adds its own protocol header, which naturally increases the size of the network packet. , but the physical link cannot transmit data packets of any size, so in Ethernet, the maximum transmission unit (MTU) is stipulated to be 1500 bytes, which also specifies the maximum IP packet size for a single transmission.

When the network packet exceeds the MTU size, it will be fragmented at the network layer to ensure that the fragmented IP packet will not exceed the MTU size. If the MTU is smaller, more packets are needed, so the network throughput capacity On the contrary, if the MTU is larger, the smaller the packets required, the better the network throughput will be.

After knowing the TCP/IP network model and the encapsulation principle of network packets, you must have guessed what the Linux network protocol stack looks like. It is actually similar to the four-layer structure of TCP/IP:

Subvert your understanding of operating systems - an overview of Linux distributions
From the network protocol stack in the picture above, you can see:

•The application needs to interact with the Socket layer through system calls;

•Below the Socket layer are the transport layer, network layer and network interface layer;

•The bottom layer is the network card driver and hardware network card device;

Linux process of receiving network packets

The network card is a piece of hardware in the computer that is responsible for receiving and sending network packets. When the network card receives a network packet, it will put the network packet into the Ring Buffer through DMA technology. This is a ring buffer. The buffer is in the network card driver in kernel memory.

After receiving the network packet, how should we tell the operating system that the network packet has arrived?

The simplest way is to trigger an interrupt, that is, every time the network card receives a network packet, it triggers an interrupt to tell the operating system.

However, there is a problem. In a high-performance network scenario, the number of network packets will be very large, and a large number of interrupts will be triggered. You must know that when the CPU receives an interrupt, it will stop what it is doing. To process these network packets, only after the processing is completed, will they go back to continue other things. Triggering interrupts so frequently will cause the CPU to have endless processing interrupts, and other tasks may not be able to move forward, thus affecting the system. Overall efficiency.

So in order to solve the performance overhead caused by frequent interrupts, the Linux kernel introduced the NAPI mechanism in version 2.6, which mixes "interrupts and polling" to receive network packets. Its core concept is not to use interrupts. method to read data, but first use the interrupt to wake up the service program for data reception, and then use the poll method to poll the data.

For example, when a network packet arrives, the network card initiates a hardware interrupt, and then the network card hardware interrupt processing function is executed. After the interrupt processing function is processed, it is necessary to "temporarily mask the interrupt", and then wake up the "soft interrupt" to poll and process the data. The interruption is not resumed until there is no new data. In this way, one interruption processes multiple network packets, thus reducing the performance overhead caused by the network card interruption.

How does soft interrupt handle network packets? It will copy the data from the Ring Buffer to the kernel struct sk_buff buffer, so that it can be handed over to the network protocol stack as a network packet for layer-by-layer processing.

First, it will enter the network interface layer. At this layer, the legality of the packet will be checked. If it is illegal, it will be discarded. If it is legal, the type of the upper layer protocol of the network packet will be found, such as IPv4 or IPv6. , then remove the frame header and frame trailer, and then hand it over to the network layer.

At the network layer, take out the IP packet and determine the next direction of the network packet, such as whether to hand it over to the upper layer for processing or forward it. When it is confirmed that the network packet is to be sent to the local machine, it will look at the IP header to see whether the type of the upper layer protocol is TCP or UDP, then remove the IP header, and then hand it to the transport layer.

The transport layer takes out the TCP header or UDP header, uses the four-tuple "source IP, source port, destination IP, destination port" as an identifier to find the corresponding Socket, and copies the data to the Socket's receive buffer.

Finally, the application layer program calls the Socket interface to read the newly arrived data from the kernel's Socket receiving buffer to the application layer.

At this point, the receiving process of a network packet has ended. You can also see the process of receiving network packets from the left part of the figure below. The right part is just the opposite, which is the process of sending network packets.

Subvert your understanding of operating systems - an overview of Linux distributions

Linux process of sending network packets

As shown in half of the picture above, the process of sending network packets is exactly opposite to the receiving process.

First, the application will call the interface of Socket to send data packets. Since this is a system call, it will fall from the user mode to the Socket layer in the kernel mode. The Socket layer will copy the application layer data to the Socket sending buffer. .

Next, the network protocol stack takes out the data packet from the Socket send buffer and processes it layer by layer from top to bottom according to the TCP/IP protocol stack.

If the TCP transmission protocol is used to send data, the TCP header will be added to the transport layer and then handed over to the network layer. The network layer will add an IP packet to the data packet, and then confirm the next hop IP by querying the routing table. And fragmented according to MTU size.

The fragmented network packet will be sent to the network interface layer, where the MAC address of the next hop will be obtained through the ARP protocol, and then the frame header and frame trailer will be added and placed in the packet sending queue.

After these are prepared, a soft interrupt will be triggered to tell the network card driver that there are new network packets that need to be sent. Finally, the driver reads the network packets from the packet sending queue through DMA and puts them into the hardware network card. queue, and then the physical network card sends it out.

Summarize

Computers are usually connected together by network devices such as communication network cards, switches, routers, etc. Due to the heterogeneity of network devices, the International Organization for Standardization has defined a seven-layer OSI network model. However, this model has It is relatively complicated and is not used in actual applications. Instead, a more simplified TCP/IP model is used. The Linux network protocol stack is implemented according to this model.

The TCP/IP model is mainly divided into four layers: application layer, transport layer, network layer, and network interface layer. Each layer has different responsibilities. This is also the main component of the Linux network protocol stack.

When the application sends a data packet through the Socket interface, the data packet will be processed layer by layer from top to bottom by the network protocol stack before being sent to the network card queue, and then the network card will send the network packet out.

When receiving a network packet, it must also be processed layer by layer from bottom to top of the network protocol stack before it is finally sent to the application program.

In short, Linux, as a free and open source operating system, has emerged in the field of technology and has been widely used. Whether you are an experienced programmer or an ordinary user, choosing a Linux distribution that suits you can really bring many unexpected benefits. I believe this article can help you better understand the Linux distribution, and I hope you can experience the charm of Linux on your own computer.

The above is the detailed content of Subvert your understanding of operating systems - an overview of Linux distributions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

See all articles