问题描述
我已经设置堆栈大小为2000KB通过的ulimit -s 2000年的ulimit -Ss 2000硬性限制。而在下面的节目,我已经拨出appox 2040000(510000×4),这是比我少的限制即字节,. 2048000(2000 * 4)字节,但是我看到我的程序崩溃!任何人都可以说明为什么发生这种情况。
I have set stack size to 2000Kb by ulimit -s 2000 and ulimit -Ss 2000 for hard limit. And in the below program i have allocated appox 2040000(510000 x 4) bytes which is less than i limited i.e,. 2048000(2000*4)bytes but i see that my program crashes! Can anybody suggest why this happens.
#include <stdio.h>
#include <malloc.h>
int main()
{
int a[510000] = {0};
a[510000] = 1;
printf("%d", a[510000]);
fflush(stdout);
sleep(70);
}
编辑1:崩溃不是因为数组索引越界,因为我试图降低指数仍然崩溃。这仅当我被限制的ulimit发生。
EDIT 1: Crash is not because of the array index out of bound as i tried lower index and still crashes. This happens only when i limit by ulimit.
推荐答案
int类型的[510000]
就会从索引数组 0
到 509999
。 A [510000]
是数组范围之外。
int a[510000]
will be an array with index from 0
to 509999
. a[510000]
is outside the array range.
这篇关于PROC崩溃,即使它比分配受到ulimit更少的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!