computer basics

1. Why learn computer basics?

           Many people think that they have a little basic knowledge and just want to type code directly. However, I feel the basics are important. Just like building a building, you have to lay the foundation first and then build the house.    

   Python is a programming language, that is, a language in layman's terms.

   We all know that there are many languages ​​in the world, such as: Chinese, English, Arabic and many other languages. To communicate with people in these languages, if you want to speak to British people, you must know English. And our computer has its own language. If you want the computer to help us do things, you need to communicate with it. Then you have to know the computer language, which is programming. Of course, computers also have many languages, such as: C, Java, PHP, Python, C# and so on. So let's start by learning the basics first. Some people also say that learning basic theoretical knowledge is boring, but that is still to be learned. You have to take it as your own interest and invest it little by little, I believe you will be great.

    A program is written in a programming language, and the final result of development is a software. Just like everyone knows QQ, Tencent Video, Kugou Music and a series of software. For these software to run, there must be a system to control it. Of course, someone will ask: Why use an operating system? Of course, those programmers from a long time ago did have no operating environment, and programming languages ​​were written to operate on hardware. You may think it's okay, but it's actually a serious problem. If it has been as before, it will seriously affect the efficiency. The operating system appears on top of the hardware and is used to control the hardware. Therefore, when we develop, we only need to call the simple interface provided by the operating system for us.

As shown in the figure above, I divided the computer system into the above three blocks. Hardware, operating system, applications. If you want to learn software knowledge, I think you need to know more or less about hardware knowledge. Now let's talk about hardware knowledge.

Second, the introduction of computer hardware

    1. The purpose of the hardware: to run some instructions given to it by the software. We can preferentially extract these three main things from the hardware, namely: CPU, memory, hard disk

       2. In real life, the human brain is used for calculation. In the computer, what is used for calculation? Of course it's the CPU. Most CPUs have two modes, kernel mode and user mode. The kernel mode and user mode here will be discussed in the following.

       3. If we understand the computer as the human brain, we can summarize it in a few sentences:

               CPU is the human brain, responsible for computing

        Memory is human memory, responsible for temporary storage

        The hard disk is a person's notebook, responsible for permanent storage

        The input device is the human ear or eye, which is responsible for receiving external information and passing it to the CPU

        All the above devices are connected through a bus, which is equivalent to a human nerve

3. Processor (registers and switching between kernel mode and user mode)

   1. The brain of the computer is the CPU, which fetches instructions from memory - ▶ decodes - ▶ executes, and then fetches instructions, decodes, executes, and repeats until the entire program is executed.

   2. A register is a storage device, and the fastest storage device is a register.

      3. Classification of registers

      ① General-purpose registers: used to save variables and temporary results.

      ②Program counter: It holds the memory address of the next instruction to be fetched. After an instruction is fetched, the program calculator is updated to execute subsequent instructions

      ③ Stack pointer: It points to the top of the current stack in memory. The stack contains one frame for each process that has entered but not yet exited. Related input parameters, local variables, and temporary variables that are not stored in registers are stored in the stack frame of a procedure

      ④Program Status Word Register (PSW for short): This register contains barcode bits (set by comparison instructions), CPU priority, mode (user mode or kernel mode), and various other control bits. Users typically read in the entire PSW, but only write to a small number of fields. In system calls and I/O, PSW is very important.

    4. Kernel mode and user mode

       Most CPUs have two modes, kernel mode and user mode.        

    ①When the cpu is in the kernel state, it runs the operating system and can control the hardware (the instruction set of all cpus can be obtained)     

    ②When the CPU is in the user state, the user software is running and cannot control the hardware (a subset of the instruction set of all CPUs can be obtained, and the subset does not include the instruction set for operating the hardware)

   Some people here may be vague about what is kernel mode and what is user mode? Let me explain:

    Kernel state: When the cpu runs in the kernel state, the cpu can execute all the instructions in the instruction set. Obviously, all the instructions contain all the functions of using the hardware, (the operating system runs in the kernel state, so that the entire hardware can be accessed) Therefore, in the final analysis, it is the same as explained in ① above.

    User mode: The user program runs in user mode, and can only execute a subset of the entire instruction set of the cpu. This subset does not contain parts that operate hardware functions. Therefore, in general, in user mode, related I/O and Memory protection (the memory occupied by the operating system is protected and cannot be occupied by other programs). Of course, in user mode, setting the mode in the PSW to kernel mode is also prohibited.

  5. Switch between kernel mode and user mode

      Software working in user mode cannot operate hardware, but like some of our software, such as Baofengyinying and other software, if we want to read a movie file from the disk, we have to switch from user mode Into the kernel mode, for this, the user program must use the system call (system call), the system call is trapped in the kernel and calls the operating system, the TRAP instruction switches the user mode to the kernel mode, and enables the operating system to obtain services.

4. Memory series, L1 cache, L2 cache, memory ( RAM ), EEPROM and flash memory, CMOS and BIOS battery

       1. The second most important thing in a computer is storage. Everyone is obsessed with storage: fast speed (so the delay of CPU waiting for memory is reduced) + large capacity + cheap price. Then it is impossible to have all three at the same time, so there are different processing methods as follows

It can be clearly seen from the above figure that register storage is very fast, but its capacity is very small. Down is the cache. I will not introduce them one by one, I believe that everyone should be able to understand this picture.

 2. The register is the L1 cache: it is made of the same material as the cpu, and it is as fast as the cpu, so the cpu accesses it without delay. The typical capacity is: 32*32 in 32-bit cpu, 64*64 in 64-bit cpu , in both cases the capacity is <1KB.

   3. The cache is the L2 cache: the access to the cache is mainly controlled by the hardware. There are cache lines in the memory according to 0~64 bytes as row 0, and 64~127 as row 1. . . The most frequently used cache lines are placed inside or very close to the CPU's cache. When a program needs to read a memory word, the cache hardware checks to see if the required cache line is in the cache.

   4. Memory: The main memory is usually called random access storage RAM, which is what we usually call memory. The capacity has been increasing. All the items that cannot be found in the cache will be found in the main memory. The main memory is volatile. Storage, all data disappears after power failure

   5. EEPROM (Electrically Erasable PROM, electrically erasable programmable ROM) and flash memory (flash memory) are also non-volatile. Another type of memory is CMOS, which is volatile and many computers use CMOS memory to keep the current time and date . The CMOS memory and the circuit that increments the time are powered by a small battery , so even if the computer is not powered on, the time can still be updated correctly, in addition to that CMOS can hold configuration parameters, such as which one is the boot disk, etc. , The reason for using CMOS is that it consumes very little power. A factory original battery can often be used for several years, but when the battery fails, the relevant configuration and time will be lost.

 

 

5. Disk

1. A disk consists of heads, tracks, and sectors.

2. Track: each head can read a new area. Combine all the tracks on a Godin's arm to form a cylinder

3. Each track is divided into several sectors, and the typical value of the sector is 512 bytes.

4. The data is stored in a segment of sectors, that is, a small circle of the circle of the track. Reading a segment of data from the disk requires seek time and delay time. So what are seek time and delay time?

    Average seek time: The time when the robotic arm randomly moves from one cylinder to an adjacent cylinder becomes the seek time. When the track is found, it means that the circle where the data is located is recruited, but the specific circle of the data is unknown. specific location

    Average delay time: After the robotic arm reaches the correct track, it must wait to rotate to the sector where the data is located, which becomes the delay time

 

6. Tape

1. Some people will wonder what tapes are used for? Of course, it is also one of the memory, which is used to store things, its storage capacity is quite large, and the price is also cheap. In the event of an emergency such as a fire, tapes can be used to store our important documents. Often used for backups (common in large database systems). However, it also has the disadvantage that it runs very slowly and is inefficient.

2. CPU and memory are not the only resources that the operating system needs to manage, and I/O devices are also a very important part. An I/O device generally consists of two parts: the device controller and the device itself .

The function of the controller : Usually the control of the equipment is very complex and specific. The task of the controller is to shield these complex and specific tasks for the operating system and provide the operating system with a simple and clear interface.

The device itself : has a relatively simple interface and is standard, so that everyone can write drivers for it. In order to call the device, a complex and specific program must be written according to the interface, so the controller provides the device driver interface to the operating system. Device drivers must be installed into the operating system.

6. Tape

1. Some people will wonder what tapes are used for? Of course, it is also one of the memory, which is used to store things, its storage capacity is quite large, and the price is also cheap. In the event of an emergency such as a fire, tapes can be used to store our important documents. Often used for backups (common in large database systems). However, it also has the disadvantage that it runs very slowly and is inefficient.

2. CPU and memory are not the only resources that the operating system needs to manage, and I/O devices are also a very important part. An I/O device generally consists of two parts: the device controller and the device itself .

The function of the controller : Usually the control of the equipment is very complex and specific. The task of the controller is to shield these complex and specific tasks for the operating system and provide the operating system with a simple and clear interface.

The device itself : has a relatively simple interface and is standard, so that everyone can write drivers for it. In order to call the device, a complex and specific program must be written according to the interface, so the controller provides the device driver interface to the operating system. Device drivers must be installed into the operating system.

 

7. Bus

    North Bridge or PCI Bridge: Connecting high-speed devices

     South bridge is ISA bridge: connecting slow devices

Eight, operating system startup process

  1. Power up the computer

  2. BIOS starts to run and detects hardware: cpu, memory, hard disk, etc.

  3. BIOS reads the parameters in the CMOS memory and selects the boot device

  4. Read the content of the first sector from the boot device (MBR master boot record is 512 bytes, the first 446 are boot information, the last 64 are partition information, and the last two are flag bits)

  5. According to the partition information, read the bootloader to start the loading module and start the operating system

  6. The operating system then asks the BIOS for configuration information. For each device, the system checks whether its device driver exists, and if not, the system asks the user to follow the device driver. Once all device drivers are available, the operating system calls them into the kernel. Then initialize the relevant tables (such as the process table), wear the required processes, and start the login program or GUI on each terminal

Nine, the application startup process

  1. Double click the shortcut

  2. Tell the operating system a file path

  3. The operating system reads the file from the hard disk into the memory

  4.CPU reads data from memory and executes

 

Operating system development history and multi-channel technology

  1. The first generation of computers (1940~1955): vacuum tubes and punch cards

    Features: There is no concept of an operating system, and all programming is directly controlling the hardware.

    Advantages: Everyone can debug the code and find bugs by himself.

    Disadvantage: Waste of computer resources.

  2. The second generation of computers (1955~1965): transistors and batch processing systems

    Features: Put the code together, let one CPU share, but still run one by one, or sequential algorithm (serial)
    Advantages: batch processing, saving time.
    Disadvantages: Some people are involved, the trouble of moving around, slowing down the speed of the program

  3. The third generation of computers (1965~1980): integrated circuit chips and multiprogramming

    The operating system of the third-generation computer widely uses the key technology that the operating system of the second-generation computer does not have: multi-channel technology

    Multi-channel technology: (referring to multiple programs/programs)
       1. Spatial multiplexing: memory should support running into multiple programs at
       the same time 2. Time multiplexing: multiple programs should allow them to switch (when Want to cut? A program takes too long to cut; when the CPU encounters IO blocking, the waiting time should be cut)

  4. Fourth generation computer (1980~present): personal computer

 Why use an operating system?

Programmers cannot understand all the details of hardware operations. It is very tedious work to manage these hardware and optimize their use. This tedious work is done by the operating system. With him, programmers can benefit from these tedious work. Freed, you only need to consider the writing of your own application software. The application software directly uses the functions provided by the operating system to indirectly use the hardware.

The two functions of the operating system

  1. Provides an abstraction for how the application uses hardware resources

  2. Order the competition of multiple programs for hardware (manage applications)

Classification of computer languages

   Machine language:
     Features: Write programs with 0s and 1s that the computer can understand
     Advantages: Program runs fast
     Disadvantages: Low development efficiency
  Assembly language:
     Features: Use some English labels instead of a string of binary numbers to write programs
     Advantages: Compared with machine language Better, a lot of assembly language is used in the operating system (the operating system does not need a network, so the speed is getting better and better). For
          example: the calling code of the process is written in assembly language.   Disadvantages
     : low development      efficiency Read and understand (English) characters to write programs      Advantages: high development efficiency      Disadvantages: slow running speed, must be translated in order for the computer to recognize, resulting in slow running speed   The above conclusions: development efficiency from low to high, running speed from low to low High, learning difficulty from difficult to easy.




 

Network Basics

1. What does the network mean?

  Computers are connected together by a physical link medium (network device).

  Communication between computers based on network protocols (network protocols are equivalent to English in the computer world)

2.OSi seven-layer protocol:

Internet protocols are divided into seven layers of osi or five layers of tcp/ip or four layers of tcp/ip according to different functions.

 

Each tier runs common physical devices:

 

 

3. Explanation of the five-layer model

Physical layer: Origin: To communicate between computers, they must access the Internet. The implication is that computers must complete networking.

        Function: mainly based on electrical characteristics to send high and low voltage, high voltage corresponds to digital 1, low voltage corresponds to digital 0 (provides electrical signals)

data link layer:

       1. Origin: Simple electrical signals 0 and 1 have no meaning, and the number of bits of the electrical signal must be specified

       2. Function: defines the grouping method of electrical signals

       3. Ethernet protocol ethernet: In the early days, each company had its own grouping method, and later a unified standard was formed, namely the Ethernet protocol ethernet

       4. The Ethernet protocol ethernet stipulates:

      1. A group of electrical signals form a data packet, called a "frame"

      2. Each data frame is divided into two parts: header head and data data

          head contains: sender/source address, 6 bytes

                             recipient/destination address, 6 bytes

                             Data type: 6 bytes

          data contains: the specific content of the data packet (minimum 64 bytes, maximum 1500 bytes)

    5. mac address: ethernet stipulates that all devices connected to the internet must have a network card. The addresses of the sender and receiver refer to the address of the network card, that is, the mac address.

    6. Broadcast: With the mac address, two machines in the same network can communicate (one host obtains the mac address of the other host through the arpmac protocol)

Network layer:

   1. Origin: With ethernet, mac address, and broadcast sending method, computers can communicate with each other. The problem is that the world-wide Internet is composed of small local area networks that are isolated from each other, so send a message to the world. can be received, which will lead to very low efficiency. So, must find a way to distinguish whether the computer is in the local area network or not in the local area network. If it is in the same local area network, it will be sent by broadcasting, if not, it will be sent by routing.

   2. Function: A new set of addresses is introduced to distinguish different broadcast domains/subnets. This set of addresses is the network address.

     3. IP address: The protocol that specifies the network address is called ip address, and the V4 version, namely ipv4, is widely used, which specifies that the network address is represented by 32-bit binary.

               Range: 0.0.0.0-255.255.255.255

     An ip address is usually written as a four-segment decimal number, for example: 172.16.10.1

     4. Subnet mask: The so-called "subnet mask" is a parameter that represents the characteristics of the subnet. It is formally equivalent to an IP address and is also a 32-bit binary number with all 1s for the network part and all 0s for the host part. For example, for the IP address 172.16.10.1, if it is known that the network part is the first 24 bits and the host part is the last 8 bits, then the subnet mask is 11111111.11111111.11111111.00000000, which is 255.255.255.0 in decimal.

    Knowing the "subnet mask", we can judge whether any two IP addresses are in the same subnet. The method is to perform AND operation on the two IP addresses and the subnet mask respectively (both digits are 1, the operation result is 1, otherwise it is 0), and then compare whether the results are the same, if so, it means that they are in the same subnet. network, or not.

     5.arp protocol: that is to say, the IP address is resolved into a mac address.

Transport layer:

   1.  Origin: We found a specific host through ip address and mac address. How to identify the application on this host, the answer is the port. The port is the number associated with the application and the network card.

     2. Function: Establish port-to-port communication.

   3. TCP: Through a two-way link, after the client sends a message to the server, it waits for the server to reply to the message before it is successfully sent.

      Cons: slow

      Advantages: Reliable (reliable when the other party has to respond to a packet to ensure successful transmission)

   4.UDP: No link, send directly.

 

       Cons: Unreliable

       Advantage: fast

    5. Three handshake (connect) and four wave (disconnect):

      The purpose of the three-way handshake is to establish a two-way communication link. SYN represents a request sent by the client to the server, and ACK represents the response sent by the server to the client.

      A three-way handshake is like a relationship and a four-way wave is like a breakup. This is just an example here.

 

Application layer:

   Origin: All users use application programs, and they all work at the application layer. The Internet is developed, and everyone can develop their own applications. There are various types of data, and the organization of the data must be specified. 

     Function: Specifies the data format of the application.

URI (uri) Site: Example

    http://www.cnblogs.com

The above URL has three parts:

   Protocol part: http:// application layer protocol

      Domain name: www.cnblogs.com

   Source: haiyan123

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325261500&siteId=291194637