官术网_书友最值得收藏!

  • Extreme C
  • Kamran Amini
  • 394字
  • 2021-03-26 16:15:41

Discovering memory structure

Unix-like operating systems provide a set of tools for inspecting the memory segments of a process. You learn in this section that some of these segments reside within the executable object file, and other segments are created dynamically at runtime, when the process is spawned.

As you should already know from the two previous chapters, an executable object file and a process are not the same thing, therefore it is expected to have different tools for inspecting each of them.

From the previous chapters, we know that an executable object file contains the machine instructions, and it is produced by the compiler. But a process is a running program spawned by executing an executable object file, consuming a region of the main memory, and the CPU is constantly fetching and executing its instructions.

A process is a living entity that is being executed inside the operating system while the executable object file is just a file containing a premade initial layout acting as a basis for spawning future processes. It is true that in the memory layout of a running process, some segments come directly from the base executable object file, and the rest are built dynamically at runtime while the process is being loaded. The former layout is called the static memory layout, and the latter is called the dynamic memory layout.

Static and dynamic memory layouts both have a predetermined set of segments. The content of the static memory layout is prewritten into the executable object file by the compiler, when compiling the source code. On the other hand, the content of the dynamic memory layout is written by the process instructions allocating memory for variables and arrays, and modifying them according to the program's logic.

With all that said, we can guess the content of the static memory layout either by just looking at the source code or the compiled object file. But this is not that easy regarding the dynamic memory layout as it cannot be determined without running the program. In addition, different runs of the same executable file can lead to different content in the dynamic memory layout. In other words, the dynamic content of a process is unique to that process and it should be investigated while the process is still running.

Let's begin with inspecting the static memory layout of a process.

主站蜘蛛池模板: 荣成市| 平乐县| 田林县| 句容市| 南昌县| 海盐县| 丰台区| 红河县| 嵊泗县| 余庆县| 余干县| 鸡东县| 确山县| 西充县| 南华县| 卓尼县| 长宁县| 丘北县| 小金县| 任丘市| 铜梁县| 元朗区| 阿图什市| 黄冈市| 安远县| 高安市| 肇庆市| 临沭县| 广河县| 本溪市| 安泽县| 双辽市| 朔州市| 南雄市| 宜宾市| 铜陵市| 淮北市| 乾安县| 定日县| 河曲县| 扎囊县|