Computer System roaming
Turing Machine: the basic idea is to use machines to simulate the mathematical operation process of people using paper and pen.
He regards this process as two simple actions:
- Write or erase a symbol on paper;
- Move your attention from one position of the paper to another;
Components of the Turing machine:
A computer is born out of the concept of a Turing Machine and can execute a computing model of a finite logical mathematical process.
Von noriman structure:The 1945-page report published in 101 not only proposed the binary concept, but also divided the computer into five main components (Memory, controller, memory, input, and output), Most of the computers we are using now are in line with the Von noriman architecture. Compared with the Turing machine, the most important breakthrough in this architecture is the increased storage, which makes the storage of programs and data possible. Therefore, the concept of data transmission (I/O) is derived, in addition, the computer network that emerged at the end of 1960s is far more simple than executing programs.
1.1 system hardware composition
Bus: A group of Electronic pipelines that run through the entire system. Information bytes are carried between each component.The bus is designed to transmit fixed-length bytes (word). The number of bytes in a word is a basic system parameter, currently, most machines have four characters in length (32-bit) or eight characters in length (64-bit ).
IO Device (input/output): the channel through which the system connects to the external device.User-input mouse and keyboard, display, data storage disk, and other network devices.
Primary storage: a temporary storage device that runs programs on the processor to store data processed by programs and programs.Physically speaking, a group of Dynamic Random storage memory (DRAM) chips are composed of a linear array of bytes, each of which has a unique address (array index ).
Processor: includes the generator and controller to explain the engine that executes commands stored in the main memory.The core of the processor is a memory register (PC). Starting from the power-on of the system, the processor has been constantly reading PC register instructions and updating the instruction registers.
Operations that the CPU may perform under the command
1.2 run the hello. c program
I recently studied Linux because of its slow progress, so I checked my computer base and switched to Linux. my operating system is ubuntu16.04LTS.
Shell is a command line interpreter that waits for your input. If the first word entered is not a built-in shell command, shell considers it an executable file.
When we press enter, shell executes a series of commands to load the executable program hello, and copies the code and data from the disk to the primary storage.
Execute the machine language commands in the main function of the hello program, copy "hello world" from the primary memory to the register, and copy the registers to the display device.
This example reveals an important issue,The system has spent a lot of time transmitting information..
The hello program is initially on the disk. When the program is loaded, it is copied to the primary storage. When the program is executed, the command is copied to the processor. The similar string "hello world" starts on the disk, is copied to the primary storage, and is finally copied to the display device.From the programmer's point of view, these replicas are overhead, and the main purpose of system design is to make these replicas as quickly as possible. To address this difference, the system designer uses a smaller and faster storage device called high-speed cache memory (cache or high-speed cache for short ).
1.3 Operating System
The operating system is regarded as a layer of software inserted between applications and hardware.
Two basic functions:
The operating system implements these two functions through several basic abstractions (processes, virtual memory, and files.
Process: abstract representation of the processor, primary memory, and IO device.
Virtual Memory: Abstraction of primary storage, disks, and I/O devices.
File: abstract representation of IO devices.
1.3.1 Process
A process is an abstraction of a running program by the operating system.
Concurrent execution: the commands of one process alternate with those of another process.
OneThe CPU executes multiple processes concurrently, which is achieved by switching between processes by the processor. The operating system's staggered execution mechanism is called "context switching ".
All status information of a process is called "context". A single processor can only process one process. When the operating system performs a process conversion, it stores the context of the current process, the context of the new process is restored, and the control is handed over to the new process.
Context switching during hello Program Execution
The shell program is being executed at the beginning, waiting for command line input. Shell executes our request through a system call, and the system call passes control to the operating system. The operating system saves the shell context, creates a new hello process and its context, and passes control to the hello process. After the hello process ends, the operating system restores the context of the shell process, and pass the control to it.
Context switching between processes is managed by the kernel of the operating system, and the kernel is the operating system code part of the memory. When an application requires certain operating system operations, such as reading and writing files, it will execute special system call commands to pass control to the kernel, then the kernel executes the request and returns the application.The kernel is not an independent process. It is a collection of code and data structures used by the system to manage all processes.
1.3.1.1 thread
Thread: The minimum unit that the operating system can schedule operations. Is the actual operating unit in the process. A thread refers to a single-Order Control Flow in a process. A process can be concurrently executed by multiple threads, and each thread executes different tasks in parallel.Multiple threads in the same process will share all system resources in the process, such as virtual address space. But multiple threads in the same process have their own call stacks, their own register environment, and their own threads are locally stored. Data is more easily shared among multiple threads.
1.3.1.2 concurrency and Parallelism
If a system supports two or more actions)Both exist, Then this system isConcurrent System. If a system supports two or more actionsExecute simultaneously, Then this system isParallel System. The key difference between the two definitions of a concurrent system and a parallel system is that"Exist"This word.
In a concurrent program, you can have two or more threads at the same time. This means that if the program runs on a single-core processor, the two threads will switch in or out of memory alternately. These threads exist at the same time-Each thread is in a certain state during execution. If the program can be executed in parallel, it must be running on a multi-core processor. At this point, each thread in the program will be allocated to an independent processor core, so it can run at the same time.
I believe you have come to the conclusion --The concept of "parallelism" is a subset of the concept of "concurrency ".. That is to say, you can write a concurrent program with multiple threads or processes. However, if you do not have a multi-core processor to execute this program, you cannot run the code in parallel. Therefore, any programming mode or execution behavior that involves multiple execution processes when solving a single problem belongs to the scope of concurrent programming.
From: "Art of concurrency"-[us] breciz 1.3.2 virtual memory
Virtual Memory is a memory management technology in the computer system. It provides an illusion for every process that each process uses its own memory and regards the memory as a very large byte array.
In fact, each process sees the same primary memory and is separated into multiple physical memory fragments. The virtual memory technology combines memory (DRAM), flash memory, disk memory, special hardware, and operating system software to provide a seemingly unified byte array for the program.
1.3.3 File
The file is the container of the byte sequence.. Every IO Device, including disks, keyboards, monitors, and even networks, can be viewed as files. All input and output in the system are implemented by using a group of system functions called Unix I/O to call read and write files.