Maximum process stack size

George Bogatko bogatko at lzga.ATT.COM
Thu Aug 9 22:26:10 AEST 1990


> ...does this mean the stack of a process
> can grow indefinitely?

On 3B's it does.  How did we find this out?

We had a 3B that was tuned (by default!) so that MAXUMEM was *greater*
then available swap.  MAXUMEM was tuned to be ALL the available memory
which was about 16 meg,  The default swap area is 20640 blocks, or about
10.5 meg.

A user program had the following line in it:

func()
{
char buf[100];
	
	.
	.	
	strncpy(buf, str);
	.
	.	
}

Notice that it is strNcpy, and that the last parameter is missing.  This
meant that a stupid value was passed as the third parameter, which told
strncpy to copy a huge number into buf.

Notice that 'buf' is an AUTOMATIC array, which means it is on the stack.

Well, the result was that the machine slowed down real fast, soon
you couldn't get prompt from the *console*, then finally, the machine
PANIC'd and dumped core.  

This happened because the stack (by definition, at least on this machine)
grew and grew and GREW and grew, until the process size was greater then
what could be held on the swap device.  Then the machine broke.

You can force the same condition (not recommended folks, don't just
TRY this) with:

	strncpy(buf, str, 0x7fffffff);

The fix (highly recommended) was to reset MAXUMEM from it's FACTORY DEFAULT
of ALL AVAILABLE MEMORY to something less than swap size.  When the same
program was run, it still slowed down the machine real bad, but eventually
core-dumped.

BTW, the same thing, tried on our 386 machine just core-dumped.  I suppose
they don't just grow the stack.  Replys i386 gurus?

GB



More information about the Comp.unix.questions mailing list