How computers work part 2

previewfile_29534312814

Operating System

Operating system is a collective name for a set of software that manages computer resources. Currently, common operating systems include: Windows series , Unix series, Linux series , OSX series, Android series, iOS series, Hongmeng, etc.

The operating system consists of two basic functions:

  • Right, you need to manage hardware devices.

  • On the contrary, it is necessary to provide a stable operating environment for the software.

therefore,The operating system is the medium of interaction between software and hardware users.

Computer operating system

The development process of Windows, the operating system we are most familiar with,
Windows 98 => Windows 2000 => Windows XP => Windows 7 => Windows 10 => Windows 11 (latest release)

Linux operating system~~ A system that programmers must master.
It is particularly suitable for development and deployment.
The application scope of this system:
1. Server
2. Embedded devices (such as refrigerators, washing machines, air conditioners, projectors...)
3. Mobile devices

Mac operating system~~ The system used by Apple computers
is cousin to Linux.
In the beginning stage of programming, it is not suitable for using Mac computers
(note: the blogger’s first laptop in life was MacBook Air 13, which was not comfortable to use. Finally, in my freshman year I bought a new one right after school started, ε=(´ο`*)))alas!!!)
I recommend the ROG series windows computer in the same price range.

Mobile operating system

Android ~~ is essentially Linux

IOS ~~ and Mac have the same origin

Operating system positioning

Insert image description here

Hardware equipment:
When the back cover of the computer is opened, all you see are the hardware equipment
~~1. Clean dust 2. Expand memory/hard disk

Driver:
The JDBC driver is to adapt JDBC to the APIs of various database manufacturers
. Like computer adapters (adapters)
, there are many types of hardware devices and different manufacturers.
Hardware manufacturers will provide drivers while developing hardware.
The computer must have the corresponding driver installed so that the system can correctly identify the hardware device.

Operating system kernel :
~~ The core function of the operating system
=> management, which is to manage hardware devices and provide a stable operating environment for software.

System call:
The API provided by the operating system to the application program.
For example, if a program wants to operate a hardware device, it needs to first
tell the operating command to the system kernel through a system call, and the kernel calls the driver to further operate the hardware device.

Application:
~~ For example, the Java virtual machine is an application in the operating system. I will not introduce it in detail here.

What is process/task (Process/Task)

A process is an abstraction of a running program by the operating system.
In other words, you can run the process program once;
at the same time,Within the operating system, the process is the basic unit of resource allocation by the operating system.

A program that runs is a "process". If it doesn't run, it doesn't count as a process!!!

image-20230917002927281

There is an idea64.exe executable program lying on the blogger's laptop.
But I did not run it at this time (double-click to run) => What is not running is not a process!!! (What is not running is called a "program")

The process on the blogger's notebook at this moment is as follows:

image-20230917005708203

The process is an important "software resource" and is managed by the operating system kernel.

So how does the operating system kernel manage processes?

Management => Description + Organization

  • Description: Explain clearly what attributes and characteristics there are.
    Use structures ( structures in C language~~ operating systems are basically written in C/C++ ) to describe process attributes
    . This structure used to describe the process has a special function. The name is called PCB (Process Control Block)

  • Organization: string together multiple such basic units through a certain data structure, string
    together multiple PCBs through a doubly linked list (not a simple doubly linked list)

Creating a process is essentially creating a structure object like PCB and inserting it into a linked list.
Destroying a process is essentially deleting the PCB node on the linked list.
Viewing the process list in the task manager is essentially Traverse this PCB linked list

Process control block abstraction (PCB Process Control Block)

To manage any real thing inside a computer, it needs to be abstracted into a set of related and integrated data. In the Java language, we can describe this feature through classes/objects.
The characteristics of the process described in PCB are as follows:

  1. pid process identifier. (unique number)

  2. The memory pointer points to which memory it has.

  3. File descriptor table of files and other resources on the hard disk

  4. Attributes related to process scheduling~~ will be explained below

~~ 2,3 describe what hardware resources are held by the process

// 以下代码是 Java 代码的伪码形式,重在说明,无法直接运行
class PCB {
    
    
// 进程的唯一标识(唯一的数字) —— pid;
// 进程关联的程序信息,例如哪个程序,加载到内存中的区域等
// 分配给该资源使用的各个资源
// 进度调度信息
}

CPU allocation - Process Scheduling

The operating system allocates CPU resources using a time mode - different processes use CPU resources in different time periods. The
blogger's notebook has a 16-core CPU.

image-20230917154049557

8 cores and 16 threads
A CPU is divided into 8 cores, and each core can support two (hyper-threading technology).
In this case, it is regarded as 16 cores!

parallel

Microscopically, at the same moment, the processes on the two cores are executed at the same time.

concurrent

Microscopically, only one process can run on one core at the same time. But it can quickly switch processes. For
example, on the CPU core, first run QQ Music, then cctalk, and then run Drawing Pad.
Just switch. The speed is fast enough (2.5GHz, running 2.5 billion instructions per second), and it cannot be perceived by
humans at a macro level. It seems to people that these processes are running at the same time.
Example: When the light flashing frequency is high, people feel that the light is on It's always bright

What the kernel is responsible for processing cannot be perceived by applications (programmers)!! Therefore, parallelism and concurrency are often collectively referred to as concurrency!!!
Unless explicitly stated in the future, when talking about concurrency, it means parallelism + concurrency

There is an important module scheduler in the operating system, which is responsible for allowing the limited CPU to schedule and execute so many processes.

Properties related to process scheduling in PCB

  1. process status

  2. Ready state: On call, the process is ready to be executed on the CPU at any time

  3. Running state: The state of the thread executing on the CPU

  4. Blocked state: unable to execute on the CPU for a short period of time~~~~
    For example, the process is performing intensive IO operations, reading and writing data. During the process of reading and writing data, it cannot respond to the execution operations of the CPU.

  5. Priority of process
    Processes also have priorities~~Scheduling by the operating system is not uniform
    . Whoever is scheduled first will be scheduled later. Whoever is scheduled will be scheduled more, and who will be scheduled less...

  6. context

    When the operating system switches processes, it needs to record the "intermediate state" of process execution and save (=> archive)
    the next time the process is run on the CPU, it can restore the last state and continue. The context of the next execution (=> file reading)
    is essentially the content of your archive.
    The context of the process is the value of each register in the CPU.
    The register~~ is the module built into the CPU to store data. What is saved is what is saved during the running of the program. Intermediate results.

    Saving the context means saving the values ​​and records of these CPU registers into the memory.
    Restoring the context means restoring the values ​​of these registers in the memory.

  7. Accounting information

    The operating system counts the time occupied by each process on the CPU and the number of instructions executed, and
    based on this, determines how to schedule the next stage.

Memory allocation - memory management (Memory Manage)

Virtual address space~~ The memory address obtained in the program is not the address of the real physical memory, but a
virtual address after a layer of abstraction.

The pointer variable I have learned in C language, the number it stores represents the memory address,
but the memory address here is a virtual memory address, not a real physical memory address!!

Memory (physically a memory stick) can store a lot of data.
The memory can be imagined as a large corridor. The corridor is very long and
has many rooms. Each room is 1 Byte in size and each room has a number, starting from 0 and counting up in sequence.
This room number is the "address", and this address is also considered the "physical address"

Memory has an amazing feature, random access (flash)
~~ Accessing data at any address in the memory is extremely fast, and the time is almost the same
~~ It is this feature that creates the time complexity of the array descriptor operation. O(1)

For the memory space used by the process, virtual address space is introduced for "isolation"!!! The
real physical addresses are no longer directly used in the code!!! Instead, virtual addresses are used.
The operating system and specialized hardware devices are responsible for this Virtual address to physical address translation

image-20230917175631796

Virtual address space is mainly used to avoid processes affecting each other.

CE

CE is a "hacking tool" similar to it. Its function is probably to change the memory data in another process.
This thing belongs to the operating system and leaves a backdoor for programmers.
It can not target another process by directly operating the pointer in C. The memory is modified!!!
But the operating system provides us with some special system calls
~~ Through these system calls, we can manually operate the memory data in another process.

Although the processes are isolated, new problems have been introduced.
Sometimes, data interaction (cooperation) between processes is indeed required
~~ This involves inter-process communication

Inter Process Communication

The so-called inter-process communication is to find a common area ("public space") under the premise of isolation , and let two processes use this area to complete data exchange~~ It is under the premise of isolation that a small Compromise
There are many specific implementation methods for inter-process communication provided by operating systems.
Currently, the process communication mechanisms provided by mainstream operating systems include: pipes, shared memory, files ,** network,** semaphores, signals

In the Java circle, multi-process programming is not very encouraged
~~ In the Java circle, files and sockets are mainly used to complete inter-process communication.

Job
The term job is more abstract than process.
You can say that process is a concrete implementation of job,
but job is not necessarily all process.

Handle
The
system contains a lot of software resources (process is a kind of software resource).
When writing code, you need to use some software resources.
The software resources are in the operating system kernel. In the application code, it is inconvenient to operate directly. .

A handle is like a remote control. (Simple integer/number)
Software resources can be manipulated through system calls with the help of this handle.

Example:
During the Three Kingdoms era, Dong Zhuo and Cao Cao => held the emperor hostage to command the princes.
The emperor is the handle of the world and the remote control of the world.

A pointer can also be regarded as a handle. It corresponds to a memory resource.

Article summary⭐️⭐️⭐️

  1. Operating system, positioning, structure,
    applications, system calls, kernel, drivers, hardware devices.

  2. The concept of process [key content]
    A running program is a process.
    The operating system needs to manage many processes
    => description (PCB) + organization (double linked list)

    • 1).pid
    • 2).Memory pointer
    • 3).File descriptor table
    • 4).Process scheduling attributes, status, priority, context, and accounting information
      • 4).=> Essentially, it is to solve the problem of "more wolves and less meat" so that a large number of processes can run simultaneously on a small number of CPUs.
  3. The virtual address space of the process
    solves the problem of mutual influence between processes.
    By introducing the virtual address space, if the address goes out of bounds, it can be discovered in time.

  4. Inter-process communication
    uses public space to complete data interaction between processes
    using files and the network.

Guess you like

Origin blog.csdn.net/m0_73740682/article/details/132949789
Recommended