The getrusage function gets you the current usage . (see man getrusage
).
The getrlimit
in Linux would help fetching the stack size with the RLIMIT_STACK
parameter.
#include <sys/resource.h>
int main (void)
{
struct rlimit limit;
getrlimit (RLIMIT_STACK, &limit);
printf ("
Stack Limit = %ld and %ld max
", limit.rlim_cur, limit.rlim_max);
}
Please give a look at man getrlimit
.
The same information could be fetched by ulimit -s
or ulimit -a
stack size row.
Also have a look at setrlimit
function which would allow to set the limits.
But as the mentioned in the other answers if you need to adjust stack then probably you should re consider your design. If you want a big array why not take the memory from the heap ?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…