[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: recursion crash

From: Alex Turner
Subject: RE: recursion crash
Date: Mon, 29 Oct 2001 16:27:04 -0000


I would expect to it behave differently.  Any program would consume resource in this case - true functional or otherwise.  Clearly a recursive call must store the return path!

However, I would expect bash to give up when it could not acquire more resource from the computer.  This is very far from the case here.  Of the several hundred mega-bites of ram bash could have used, it uses so little my normal system monitor cannot detect it.

Thus, I would assume that the stack size is hard coded and does not increase upon demand.  This is at odds with the manual which states that 'No limit is set on the number of recursive calls." (which would imply a _system_ resource limit).

At less than 10 000 recursions, bash is crippled for many application for which it would otherwise be ideal.  I my case I am writing code to perform very long running computations using a combination of bash and C++.  The non recursive versions of the control structures are very much less elegant and so I would like to avoid them and similarly avoid re-inventing the wheel (bash is excellent in all other regards for this purpose).

Thus - with the greatest respect - I can and do expect it to behave differently ( or at the very least have a compile time directive to permit it do behave more expressively under recursion).


-----Original Message-----
From: address@hidden [mailto:address@hidden]
Sent: 29 October 2001 16:03
To: Alex Turner
Cc: 'address@hidden'
Subject: Re: recursion crash

Alex Turner <address@hidden> wrote:
> #!/usr/bin/bash
> declare -i n
> n=0
> r()
> {
>    echo $n
>    n=n+1
>    r
> }
> r
> The above script will crash bash dew to a segmentation violation.

How did you expect it to behave differently?  Your computer has only a
finite amount of memory; infinite recursion will eventually use it
all, and continue trying to use more.  A real functional program would
not use infinite recursion and would (probably) not encounter this
problem.  bash could be changed to give an error message instead of
crashing, but I imagine that might have a significant performance


reply via email to

[Prev in Thread] Current Thread [Next in Thread]