Principles of program execution (popular science)
Target
- Three things in a computer
- The principle of program execution
- The role of the program
01. The three major components of a computer
The computer contains a lot of hardware, but to run a program, there are three core hardware, namely:
- CPU
- The central processing unit is a very large-scale integrated circuit
- Responsible for processing data / computing
- RAM
- Temporarily store data (data will disappear after power failure)
- high speed
- Small space (high unit price)
- hard disk
- Permanently store data
- slow
- Large space (low unit price)
CPU | RAM | hard disk |
---|---|---|
thinking questions
- Which hardware device in the computer is responsible for executing the program?
- CPU
- Is the memory faster or the hard drive faster?
- RAM
- Are our programs installed in memory, or in hard disk?
- hard disk
- I bought a memory stick with 500G of space! ! ! ,is this sentence correct?
- No, memory sticks usually only have //
4G
/8G
16G
32G
- No, memory sticks usually only have //
- After the computer is turned off, the data in the memory will disappear , is this sentence correct?
- correct
02. The principle of program execution
- Before the program runs , the program is saved in the hard disk
- when running a program
- The operating system will first let the CPU copy the program into memory
- The CPU executes the program memory
For a program to execute, it must first be loaded into memory
2.1 Principle of Python program execution
- The operating system will first let the CPU copy the program of the Python interpreter into memory
- Python interpreter Let the CPU translate the code in the Python program from top to bottom according to the grammar rules
- The CPU is responsible for executing the translated code
How big is the Python interpreter?
- Execute the following terminal command to see the size of the Python interpreter
# 1. 确认解释器所在位置
$ which python
# 2. 查看 python 文件大小(只是一个软链接)
$ ls -lh /usr/bin/python
# 3. 查看具体文件大小
$ ls -lh /usr/bin/python2.7
Tip: The purpose of establishing a soft link is to facilitate users not to remember which
03. The role of the program
Programs are for processing data !
- News content, commentary... is data provided by news software
- Product information, delivery information provided by e-commerce software ... is data
- Motion data provided by motion software ... is data
- Map information, positioning information, vehicle information provided by map software is data
- Chat information, friend information provided by instant messaging software ... is data
- ……
3.1 Think about the startup process of the QQ program
- Before QQ runs , it is saved in the hard disk
- After running , the QQ program will be loaded into memory
3.2 Think about the login process of the QQ program
- Read the QQ number entered by the user
- Read the QQ password entered by the user
- Send the QQ number and QQ password to Tencent's server and wait for the server to confirm the user information
thinking 1
Before the QQ program sends the QQ number and QQ password to the server, do you need to store the QQ number and password?
Answer
Definitely needed! - Otherwise, the QQ program will not know what to send to the server!
thinking 2
Where does the QQ program save the QQ number and QQ password ?
Answer
Saved in memory , because the QQ program itself is in memory
thinking 3
How does the QQ program save the user's QQ number and QQ password ?
Answer
- Allocate a space for QQ number and QQ password in memory
- Before the QQ program ends, these two spaces are managed by the QQ program, and no other programs are allowed to use them.
- Before QQ is used by itself, these two spaces are always only responsible for saving QQ numbers and QQ passwords
- Use an alias mark the location of the QQ number and QQ password in memory
- Inside the program, the space allocated in memory for QQ number and QQ password is called a variable
- Programs are used to process data, and variables are used to store data