Summary of Autumn Recruitment Classics (1)

Summary of Autumn Recruitment (1) @ TOC

1. Compiled and interpreted languages

Answer: The main difference is that the source program of the former can be run on the platform after compilation, while the source program of the latter is compiled during operation. So the former runs fast, and the latter has good cross-platform performance.

compiled language

   使用专门的编译器,针对特定的平台,将高级语言源代码一次性的编译成可被该平台硬件执行的机器码,并包装成该平台所能识别的可执行性程序的格式。

features

 	在编译型语言写的程序执行之前,需要一个专门的编译过程,把源代码编译成机器语言的文件,如exe格式的文件,以后要再运行时,直接使用编译结果即可,如直接运行exe文件。因为只需编译一次,以后运行时不需要编译,所以编译型语言执行效率高。

Summarize

1. One-time compilation into platform-related machine language files, which is separated from the development environment when running, and has high operating efficiency; 2. It is related
to a specific platform and generally cannot be transplanted to other platforms;
3. Existing C, C++, Objective, etc. are all compiled languages.

interpreted language

Use a dedicated interpreter to interpret the source program line by line into machine code for a specific platform and execute it immediately. It is the code that is dynamically translated and executed line by line by the interpreter when it is executed, rather than the translation being completed before execution.

features

An interpreted language does not need to be compiled in advance, it directly interprets the source code into machine code and executes it immediately, so as long as a certain platform provides a corresponding interpreter, the program can be run.

Summarize

1. Every time an interpreted language is run, the source code needs to be interpreted as machine code and executed, which is inefficient;
2. As long as the platform provides a corresponding interpreter, the source code can be run, so it can facilitate source program porting;
3.Python, etc. are interpreted languages.

2. What are the main stages of the compilation process and the functions of each stage?

词法分析阶段:读入源程序,对构成源程序的字符流进行扫描和分解,识别出单词;
语法分析阶段:机器通过词法分析,将单词序列分解成不同的语法短语,确定整个输入串能够构成语法上正确的程序;
语义分析阶段:检查源程序上有没有语义错误,在代码生成阶段收集类型信息;
中间代码生成阶段:在进行了上述的语法分析和语义分析阶段的工作之后,有的编译程序将源程序变成了一种内部表示形式;
代码优化:这一阶段的任务是对前一阶段产生的中间代码进行变换或进行改造,目的是使生成的目标代码更为高效,即省时间和省空间;
目标代码生成:这一阶段的任务是把中间代码变换成特定机器上的绝对指令代码或可重定位的指令代码或汇编指令代码

3. The difference between process, thread and coroutine:

1. The process is the unit of resource allocation.
2. The thread is the unit of operating system scheduling.
3. Process switching requires a lot of resources, but the efficiency is very low. 4. The resources required for thread switching are average, and the efficiency is average
.

4. What are the states of the process?

Creation state: The process is being created and has not yet reached the ready state.
Ready state: The process is already in the ready-to-run state, that is, the process has obtained all the required resources except the processor, and can run once the processor resource (time slice allocated by the processor) is obtained. Running state: The process is running on the processor (only one process is running at any time under a single-core CPU )
.
Even if the processor is idle, the process cannot run.
End state: The process is disappearing from the system. It may be that the process terminated normally or was interrupted and exited for other reasons.

5. Communication between processes

1. Pipe Anonymous pipe: used for communication between parent-child processes or sibling processes with kinship
2. Famous pipe: Since anonymous pipe has no name, it can only be used for inter-process communication of kinship. To overcome this shortcoming, well-known pipelines are proposed. Well-known pipes strictly follow first-in, first-out. Well-known pipes exist in the form of disk files, which can realize communication between any two processes on the machine.
3. Signal: Signal is a relatively complex communication method used to notify the receiving process that an event has occurred
4. Message queue: Message queue is a linked list of messages with a specific format, stored in memory and identified by a message queue identifier. The communication data of pipelines and message queues are based on the first-in-first-out principle. Unlike pipes (unnamed pipes: only exist in memory files; named pipes: exist in actual disk media or file systems), message queues are stored in the kernel, and only when the kernel is restarted (that is, the operating system is restarted) or when a message queue is explicitly deleted, the message queue will be actually deleted. The message queue can realize random query of messages. The messages do not have to be read in the order of first in first out, but can also be read according to the type of the message, which has more advantages than FIFO. The message queue overcomes the shortcomings of the small amount of information carried by the signal, the pipeline can only carry the unformatted byte stream, and the buffer size is limited.
5. Semaphore: A semaphore is a counter used for multi-process access to shared data. The purpose of the semaphore is to synchronize between processes. This type of communication is mainly used to solve synchronization-related problems and avoid race relationships.
6. Shared memory: Multiple processes can access the same memory space, and different processes can see the update of the data in the shared memory by the other process in time. This method needs to rely on some kind of synchronization operation, such as mutex and semaphore. This is arguably the most useful form of interprocess communication.
7. Socket: This method is mainly used to communicate between the client and the server through the network. Socket is the basic operation unit of network communication that supports TCP/IP. It can be regarded as the endpoint of two-way communication between processes between different hosts. Simply put, it is an agreement between the two parties of communication, and the related functions in socket are used to complete the communication process.

Guess you like

Origin blog.csdn.net/hitxqy/article/details/107412218
Recommended