1

when i type "limit" in my machine:

the output will be:

cputime      unlimited
filesize     unlimited
datasize     unlimited
stacksize    8192k
coredumpsize unlimited
memoryuse    unlimited
vmemoryuse   unlimited
descriptors  32768
memorylocked 32 kbytes
maxproc      385318

But i want to make the stacksize to unlimited so i type "unlimit" in my linux konsole to make it unlimited.

However I want it to be changed automatically in my c++ program.How can I do it?

Jaden Ng
  • 141
  • 1
  • 12

1 Answers1

1

Use the setrlimit() system call. Specify the RLIMIT_STACK as the resource and RLIM_INFINITY as the new limit.

http://linux.die.net/man/2/setrlimit

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • You might want to mention:If the user's hard limit allows RLIM_INFINITY. – jim mcnamara Jun 07 '13 at 03:01
  • 1
    @jimmcnamara He said he was able to unlimit in the shell, which implies he has permission. Anyway, this is the way to try to set it to unlimited -- if he doesn't have permission, it will return an error. – Barmar Jun 07 '13 at 03:03
  • @Barmar Thank you for the answer.I will try it later.May I know if without permission there is no way to do the changes right? – Jaden Ng Jun 07 '13 at 03:08
  • Right. That's the point of permissions, they prevent you from doing things if you don't have them. – Barmar Jun 07 '13 at 03:10
  • @Barmar This is what I see from other's code "const rlim_t kStackSize = 64L * 1024L * 1024L; // min stack size = 64 Mb" where what if i want to set min stack is 8192kb how can i do that? – Jaden Ng Jun 07 '13 at 03:27
  • 8192L*1024L, what's the problem? – Barmar Jun 07 '13 at 03:34
  • @Barmar The code show above is 64L*1024L*1024L for min stack 64mb.I am not sure how to make min stack to 8192kb. So is just 8192L*1024L ? Btw I want to make the stacklimit to be unlimitted.How can I do that? I am trying to modify from this code http://stackoverflow.com/questions/2279052/increase-stack-size-in-linux-with-setrlimit – Jaden Ng Jun 07 '13 at 03:41
  • 1kb is 1024, so if you want 8192kb you multiply 8192 by 1024, it's simple arithmetic, nothing complicated. If you want unlimited, use RLIM_INFINITY, like I said in my answer. – Barmar Jun 07 '13 at 03:44
  • @Barmar Ya.Just to make sure I am right with the arithmetic.Thanks very much. – Jaden Ng Jun 07 '13 at 03:47