It is mentioned here that "Programs executed in the operating system run as processes with lower permissions." In fact, the operating system allocates space and executes processes in units. But what is the difference between a process and a program? We say that
A program is a set of instructions that are statically stored in a memory such as a disk;
When a program is executed by the operating system, it will be loaded into the memory space and logically generate an independent instance, which is a process.
This is like saying that the program is a recipe, and the instructions in it are to instruct you to open the fire and add salt; the process is the cooking process. The operating system cooks meticulously according to the instructions, and the result is Our dishes.
As CPU frequency growth gradually stagnated, CPUs began to develop in the direction of multi-core. In order for multiple CPU cores to work for us at the same time and perform tasks in parallel, the concept of threads needs to be involved. Thread in English is Thread, sometimes also called lightweight process. It is the smallest unit for task scheduling by the operating system. Threads live in the process; threads in the same process share a virtual memory space and the resources therein; threads each hold their own thread ID, current instruction pointer (PC), register set and stack.
Generally speaking, using multi-threading (one core pretending to be multiple cores) will bring some advantages:
The time waiting for I/O operations will be scheduled to other Thread execution improves CPU utilization;
Leave computing-intensive operations to worker threads, and reserve threads to maintain interaction with users;
Under multi-CPU/multi-core computers, Effectively consumes computing power;
Compared with multi-process programs, data sharing is more efficient (in the same process space).
Regarding the two concepts of operating system and operating system kernel, many people try to distinguish and explain it, but find it difficult to explain it completely (including myself, here I just sort out my own understanding, there are If there is something wrong, I hope everyone will criticize and correct it so that we can make progress together).
I checked some conceptual explanations about the operating system kernel on the Internet and in CS series books. After summarizing, my understanding is:
(1) The operating system includes the operating system kernel ( This is inevitable), that is to say, the kernel program is a subset of a set of computer programs included in the operating system, so the kernel program is also a set of computer programs, and these kernel programs are the most commonly used basic modules in the operating system. Works directly with hardware and consists primarily of those parts that manage memory, files, peripherals, and system resources.
(2) The kernel program always occupies a section of memory in the memory, so that the processor can call these kernel programs at any time;
(3) In addition to the kernel program, the operating system also has Including some other basic components, such as text editors, compilers, programs used to interact with users, etc.
For point (2), you can introduce the book "In-depth Understanding of Computer Systems" about "Virtual Memory" (P12) explains it with a picture, as follows:
In the above figure, in the description of the virtual address space of the process, the top sub-area "Kernel Virtual Memory" is used To store kernel programs and data, this address space is a fixed structure, so for each application (process), it has the same structure of virtual address space, which ensures that each process can call the operating system Kernel program to complete its own functions.
Let’s use another picture to illustrate that the operating system kernel is a group of sub-processes of the operating system
In the above picture, the operating system kernel surrounds the hardware, and at the same time, its outer layer is the system Call interface, which is the other components of the operating system other than the kernel.
The following is a summary of two netizens’ explanations about operating systems and operating system kernels. I personally think the explanations are relatively good:
(1) The kernel is the basic module of the operating system. Used to manage system resources. For example, it provides software-level abstraction (such as operation and permission control of objects such as processes, file systems, synchronization, memory, network protocols, etc.), and abstraction of hardware access (such as disk, display, network interface card (NIC)); The operating system is an extension of the kernel and includes system components that provide basic services.
(2) The kernel is an operating system in the computer science sense. It interacts directly with the hardware and provides CPU time slice management, interrupts, memory management, IO management, etc.; an operating system in a general sense includes There needs to be more stuff, at least a basic program for user interaction, such as a command line interface and basic instructions (file traversal, process management, etc.), or a graphical interface desktop and file browser.
Standard C library handling of write(). The library provides a portion of the system-call interface for many versions of Unix and Linux.