Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Greg Wooledge
On Fri, Dec 10, 2010 at 03:23:46PM +0100, Diggory Hardy wrote: > What if bash were only to allow scripts to call themselves with exec? You can't prevent programmers from writing horrible code. At some point, it isn't worth the effort even to try.

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Pierre Gaston
On Fri, Dec 10, 2010 at 11:25 AM, Diggory Hardy wrote: > On Thursday 09 December 2010 Pierre Gaston wrote: >> On Wed, Dec 8, 2010 at 11:15 AM, Diggory Hardy >> wrote: >> > Hello, >> > >> > With a simple script such as that below, bash can enter an infinite loop >> > of eating memory until the s

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Diggory Hardy
On Friday 10 December 2010 Greg Wooledge wrote: > On Fri, Dec 10, 2010 at 03:23:46PM +0100, Diggory Hardy wrote: > > What if bash were only to allow scripts to call themselves with exec? > > You can't prevent programmers from writing horrible code. At some point, > it isn't worth the effort even

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Marc Herbert
> What if bash were only to allow scripts to call themselves with > exec? Tail calls are not the only useful type of recursion, they're just a particular case Sometimes you do want to return (and discard some lower side-effects) (and it is not always obv

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Diggory Hardy
On Friday 10 December 2010 Pierre Gaston wrote: > On Fri, Dec 10, 2010 at 11:25 AM, Diggory Hardy > wrote: > > On Thursday 09 December 2010 Pierre Gaston wrote: > >> On Wed, Dec 8, 2010 at 11:15 AM, Diggory Hardy > >> wrote: > >> > Hello, > >> > > >> > With a simple script such as that below,

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Greg Wooledge
On Fri, Dec 10, 2010 at 10:25:02AM +0100, Diggory Hardy wrote: > Uh. Then over time it is legitimate to have a script recursively call itself > a few thousand times with each instance still in memory? No. > The potential to grind the system to a complete halt is pretty serious > though. Perhaps t

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Marc Herbert
> Would it not be simple to add some kind of protection against this As already mentioned, recursion is a perfectly valid programming technique so you really cannot forbid it (in fact it is equivalent to iteration Would you also forbid a

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Diggory Hardy
On Thursday 09 December 2010 Pierre Gaston wrote: > On Wed, Dec 8, 2010 at 11:15 AM, Diggory Hardy > wrote: > > Hello, > > > > With a simple script such as that below, bash can enter an infinite loop of > > eating memory until the system is rendered unusable: > > > > #!/bin/bash > > PATH=~ > > i

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-09 Thread Pierre Gaston
On Wed, Dec 8, 2010 at 11:15 AM, Diggory Hardy wrote: > Hello, > > With a simple script such as that below, bash can enter an infinite loop of > eating memory until the system is rendered unusable: > > #!/bin/bash > PATH=~ > infinitely-recurse > > Save this as infinitely-recurse in your home dire

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-09 Thread Bob Proulx
Diggory Hardy wrote: > With a simple script such as that below, bash can enter an infinite > loop of eating memory until the system is rendered unusable: > > #!/bin/bash > PATH=~ > infinitely-recurse Yes, of course. It calls itself repeatedly and every copy consumes just a little more system res

Recursively calling a bash script goes undetected and eats all system memory

2010-12-09 Thread Diggory Hardy
Hello, With a simple script such as that below, bash can enter an infinite loop of eating memory until the system is rendered unusable: #!/bin/bash PATH=~ infinitely-recurse Save this as infinitely-recurse in your home directory and run - and make sure you kill it pretty quick. OK, so an obvio