Search code examples
c++csegmentation-faultstack-overflowmemset

Why is stack overflow not occuring?


Ubuntu

ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 62202
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 62202
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

As mentioned above max stack size is 8MB

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
  int abc[2048002];
  memset(abc,0,2048002*4);

}

In above program, I have allocated more than 8MB, even though the stack size is exceeded (max 8MB), I am not getting segmentation fault. So can anyone explain why I am not getting stack overflow in above scenario?


Solution

  • stack size              (kbytes, -s) 8192
    

    That's 8192 kilobytes, or 8 megabytes.