How to determine the stack size for a program on Linux?

How to determine the current program stack size on Linux?

it says that the stack size for each program will be 8 MB on Linux, but when you use cat / proc // mmap it shows a different size.

Also, how to determine the stack size of related threads? Since it is said that threads have their own stack?

+5
source share
2 answers

If you just need the current stack size, you can declare a variable at the top of main (), take its address and compare it with the address of the variable declared where you define "current". The difference should be the approximate size that the stack has grown.

, , /proc/ [pid]/maps, , [stack]. , atd- :

7fff72a41000-7fff72a56000 rw-p 00000000 00:00 0                          [stack]
0175b000-0177c000 rw-p 00000000 00:00 0                                  [heap]

.

, , , , . , - :)

1) , main(), alloca() , 0xDEADBEEF - ​​ , . "", .

2) main alloca(), "" , ( 64 -, , , ), , .

, , !

+3

, , , .

, , pthread.

pthread_attr_t attr;
size_t stacksize;

pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr, &stacksize); 

printf("%u\n", stacksize); 

, . 8 .

, pthread_attr_setstacksize() attr 2 pthread_create.

: , . 8 8 , .

+3

All Articles