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

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

Process memory layout

Whenever you run an executable file, the operating system creates a new process. A process is a live and running program that is loaded into the memory and has a unique Process Identifier (PID). The operating system is the sole responsible entity for spawning and loading new processes.

A process remains running until it either exits normally, or the process is given a signal, such as SIGTERM, SIGINT, or SIGKILL, which eventually makes it exit. The SIGTERM and SIGINT signals can be ignored, but SIGKILL will kill the process immediately and forcefully.

Note:

The signals mentioned in the preceding section are explained as follows:

SIGTERM: This is the termination signal. It allows the process to clean up.

SIGINT: This is the interrupt signal usually sent to the foreground process by pressing Ctrl + C.

SIGKILL: This is the kill signal and it closes the process forcefully without letting it clean up.

When creating a process, one of the first things that operating systems do is allocate a portion of memory dedicated to the process and then apply a predefined memory layout. This predefined memory layout is more or less the same in different operating systems, especially in Unix-like operating systems.

In this chapter, we're going to explore the structure of this memory layout, and a number of important and useful terms are introduced.

The memory layout of an ordinary process is divided into multiple parts. Each part is called a segment. Each segment is a region of memory which has a definite task and it is supposed to store a specific type of data. You can see the following list of segments being part of the memory layout of a running process:

  • Uninitialized data segment or Block Started by Symbol (BSS) segment
  • Data segment
  • Text segment or Code segment
  • Stack segment
  • Heap segment

In the following sections, we will study each of these segments individually, and we discuss the way they contribute to the execution of a program. In the next chapter, we will focus on Stack and Heap segments and we'll discuss them thoroughly. As part of our quest, let's introduce some tools that help us inspect the memory before going into the specifics of the above segments.

主站蜘蛛池模板: 阿合奇县| 土默特右旗| 呼玛县| 昔阳县| 车致| 临泽县| 吴忠市| 芮城县| 买车| 名山县| 灌阳县| 清流县| 固始县| 全椒县| 泾川县| 葫芦岛市| 庄河市| 临朐县| 平乡县| 南陵县| 玛曲县| 太康县| 宝兴县| 栾城县| 沐川县| 安图县| 博野县| 南靖县| 大理市| 克拉玛依市| 晋州市| 宕昌县| 锦州市| 金湖县| 济源市| 扶沟县| 淮南市| 榆社县| 墨竹工卡县| 沧源| 靖江市|