- 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.
- Advanced Quantitative Finance with C++
- Learning Java Functional Programming
- C語言程序設計教程
- 基于粒計算模型的圖像處理
- Visual FoxPro程序設計教程(第3版)
- 微服務與事件驅動架構
- SQL Server 2012數據庫技術及應用(微課版·第5版)
- 算法訓練營:入門篇(全彩版)
- 物聯網系統開發:從0到1構建IoT平臺(第2版)
- Python:Master the Art of Design Patterns
- Oracle從入門到精通(第5版)
- 零基礎入門學習Python(第2版)
- Unity&VR游戲美術設計實戰
- QGIS 2 Cookbook
- 小程序從0到1:微信全棧工程師一本通