2 ms·
They shouldn't, but they do tend to have a large quantity of memory backing them that gets added to when grown into. The kernel uses 4k, 8k, or 16k stacks; a q
by JoshTriplett 12y ago
They shouldn't, but they do tend to have a large quantity of memory backing them that gets added to when grown into. The kernel uses 4k, 8k, or 16k stacks; a quick test on a Linux x86-64 system suggests that userspace has 8M stacks by default.
Hackish test code to recurse infinitely and print the stack pointer until a segfault:
#include <stdio.h>
static inline unsigned long get_sp(void)
{
unsigned long ret;
__asm__("mov %%rsp, %0" : "=r" (ret));
return ret;
}
void main(void)
{
printf("%lu\n", get_sp());
main();
}
Running this and comparing the first and last values shows a stack size of about 8M.