Do you really understand the computer system? Chapter One: Interaction between programs and systems

Source: Internet
Author: User

With the development of computers and the advent of high-level programming languages, applications not only have to deal with hardware, but also rely on system services, which include not only the operating system, but also the compilation system, and we describe how the application deals with these systems, respectively.

Let's start with the interaction between the program and the compilation system. Today's program code is growing in size, and it is impractical to write all of the code in a single file, so the code is often broken down into different files by functionality. When a program written in a high-level language wants to be executed by the processor, it must first be compiled into binary form by the compiler of the compiled system, then the target file can be relocated, and then the linker of the system will have to link the relocatable target files to an executable file. It is no longer cumbersome for compilers to compile high-level languages, mainly to explain how the linker works.

The work done by the linker mainly consists of two parts: 1. Symbolic parsing, 2. Relocation. In a Linux system, the target file is usually in elf format (Windows is PE format), which consists of several sections, including. Text. Data. Symtab, etc.,. The text section is primarily the machine code of the compiled program, and the. Symtab section mainly stores symbols, Includes global variables, function names, and so on. When a relocatable target file is linked, it parses the symbols referenced in each relocatable target file, and if the symbol encountered does not exist in its own symbol table, it goes to the symbol table in the other target file, which links each symbol reference in the code to the defined symbolic definition. Next is relocation, where the linker merges the same types of sections of all target files into aggregation sections of the same type, assigns run-time memory addresses to those aggregation sections, and each symbol defined, and then the linker modifies each symbol's reference in the Code section and Data section to point to the run-time address of the symbol. This completes the entire link, and the resulting file is also known as the executable target file.

Then look at the interaction between the program and the operating system. Today's computers are no longer limited to the implementation of the previous single-channel program, but the concurrent execution of multi-channel programs, as we can listen to songs while playing games, that for a single-processor computer how this is implemented? Everyone must have thought of the process, there is no doubt that the concept of the process of the computer system is very profound impact is also very profound, you can carefully ponder its profundity!

The classic definition of a process is an instance of a program in execution. It provides an illusion that makes us think of ourselves as having exclusive processors and storage. First of all, the illusion of an exclusive processor, in an operating system with n processes, the n processes take turns executing a time slice and then being preempted. The sequence of values of the program counter (or PC) in each of these processes is independent of the sequence in the other process, which creates the illusion that the processor only runs its own program. Then look at the illusion of exclusive memory, on a machine with n-bit addresses, the address space is a collection of 1-2^n-1, and each process has an address space of 2^n size. Other processes cannot be accessed, as it is implemented primarily by virtual memory.

When we request blocks dynamically in the program, such as the malloc function of C, this is the virtual memory of the operating system to allocate blocks for us. Virtual memory is a perfect interaction between hardware exceptions, hardware address translation, main memory, disk files, and kernel software, which only stores the active area in main memory and transmits data back and forth between the disk and main memory as needed.

  

Do you really understand the computer system? Chapter One: Interaction between programs and systems

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.