Remember the page fault? It’s similar, but the reason is different. Page failure is inherent in virtual memory system. The segmentation failure is a bug in the code (probably).
It occurs when you try to access a memory that is not available for your application. It has not been allocated (reserved) for the running process. It also occurs when access is done on protected pages in the process, usually more when writing.
Your mistake
You cannot write to the address 0 of the memory of your application. And not only the 0, others are also reserved. Actually don’t even read 0. You can’t write in the code part (save special privilege), the code is fixed, it’s static. The same occurs with the static data part (usually placed by literals in your code).
Remembering that the memory address in question is virtual, has nothing to do with physical memory.
What is Memory Segmentation?
Areas of memory where each part is:
- the binary code running
- static data
- static memory, dynamic
- parts that only the operating system should access
- parties protected at the request of the application
- etc..
These are the segments, each with a different configuration in the operating system. These segments usually consist of several pages.
It can occur whenever you do an unauthorized operation, read, write or run. It’s like in filesystem when trying to access a file without permission for that.
How Memory Segmentation Influences How My Program Works?
To develop it common nothing, but there has every organization of how the process will treat what is in memory. Of course he cannot try to do operations in segments not allowed in the languages that allow this.
The Segmentation fault generated by the above program is related to Memory Segmentation or is something else?
This error occurs by accessing something that is not authorized in that context. This does not occur in languages with managed memory, except for bug in the Runtime or virtual language machine.
Those bugs often occur by problem handling pointers, but there are some situations that may occur.
Worse when the Segmentation fault. The hardware can not prevent all wrong access in memory because it is valid and this becomes a logical error, much more difficult to detect.
Normally on Unix systems I have segments and pages, right? In this case, is it said that a page belongs to a single segment (which in turn contains several pages), or is the opposite? Or has nothing to do with each other?
– Jefferson Quesado
My understanding is that this is correct, although virtual page and physical page are different things, you can have the same physical page being pointed out by different virtual pages, in different processes and therefore different segments, though only because they’re different processes. Segments are concepts a little more abstract and are much bigger things, so much so that there are few, pages can exist, in the extreme, billions.
– Maniero