How is the size of the process determined?

I am very new to these concepts, but I want to ask you the whole question, which I think is very simple, but I'm confused, so I ask about it. The question is ... How is the size of the process determined by the OS? Let me figure it out first, suppose I wrote a C program and I want to know how much memory it is going to take, how can I determine it? secondly, I know that there are many sections, such as a section of code, a section of data, a BSS process. Now is the size of this data predetermined? secondly, how the size of the stack and heap is determined. stack and heap size also matter while calculating the overall process size.

Again we say that when the program loads, the address space is transferred to the process (this is done by the base and limit register and is controlled by the MMU, I think), and when the process tries to access a memory location that is not in the address space, we get a segmentation error. How is it possible for a process to access memory that is not in its address space. According to my understanding, when a buffer overflow occurs, the address becomes damaged. Now that the process wants to access the damaged location, we get a segmentation error. Is there any other way to violate the address.

and thirdly, why the stack is growing down and the heap is up. This process is the same with the entire OS. How it affects performance. Why can't we have it another way?

Please correct me if I am mistaken in any of the statements.

Thanks Sohrab

+5
source share
4 answers

When the process starts, it gets its virtual address space. The size of the virtual address space depends on your operating system. In general, 32-bit processes receive 4 gigabyte (4 gigabytes) addresses and 64-bit processes, receive 18 EiB (18 exa binary) addresses.

, , , , . , , segfault.

- . , ( ). Intel 256 TiB . , . , 32- ( 4 GiB) Windows 2 GiB 2 GiB ( 1 GiB 3 GiB ).

. , , , .

, , BSS .. - , , . , , . . . : , , , - . , .

( , ) . / , , . " ", . , , , , , , .

, , , . , ( , ).

, , . , . , - , .

- -.

  • ,

  • ,

  • ,

  • ,

  • ,

  • , ,

  • , , ,

, , .

, , . RAM , . , , , , , .

+1

.

, . DLL , , , , .

, .

, , .

, , ( , , , .. ..).

, , . .

W.r.t. According to my understanding when some buffer overflows happens then the address gets corrupted. . , ? , . , . , , .

, (, , ), . . .

, , , . , .

, SO .

+1

" , ?"

. . . - , . :

 char *p = "some string";

 while (*p++ != 256)  /* Always true. Keeps incrementing p until segfault. */
     ;

, , , .

+1

№ 2 № 3.

# 2

C , , ( , . ). . , , .

, , : 0x01000 0x09000.

int * ptr = 0x01000;
printf("%d", ptr[0]); // * prints 4 bytes (sizeof(int) bytes) of your address space
int * ptr = 0x09100;
printf("%d", ptr[0]); // * You are accessing out of your space: segfault

segfault, , - NULL ( 0x00, ) .

, linux i386 , . , : .

# 3

, . i386, push pop, , . , , , , . OS .

. . , :

#include <stdio.h>

int main()
{
    int a = 10;
    printf("%p\n", &a);
    return 0;
}

If you run this program several times (even at the same time), you will see, even for different instances, the same address is printed. Of course, this is not a real memory address, but it is a logical address that will be displayed at the physical address when necessary.

0
source

All Articles