Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stack Size

Status
Not open for further replies.

mmcds

MIS
Jul 5, 2007
28
US
Can anybody explain to me what stack size acutally is and how can you ever guess what to set it to? When I do ulimit -a it shows unlimited for stack size, but I have some problems running a couple programs on my Linux box that shows a segmentation fault.
 
Segmentation faults are not generally an indicator of a stack size problem. I say generally because there are plenty of cases where a static allocation exceeds the stack size.

Code:
 #include <stdio.h>


int main(void) {
int arr_int[65000];
float too_big[20000000];
double way_too_large[20000000];

                   printf("Stack size = %d + %d + %d\n",sizeof(int) * 65000,sizeof(float) * 20000,sizeof(double) * 20000000); 
                   printf("Hmm...stack suffices.\n");
                   return 0;
}

The above for instance segfaults on my linux workstation with an 8k stack size (obviously).
To modify stack size you may end up having to recompile the kernel since the max constants are defined there.

In any case I'd strace or debug the offending processes to see where the failure is coming from definitively.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top