From: Oliver Peng Date: 2008-03-04T04:25:39+09:00 Subject: Re: SystemStackError: stack level too deep Robert Klemme wrote: > On 29.02.2008 22:15, Oliver Peng wrote: >> tcp && tcp.close >> >> After a period of time, I got the error: >> >> SystemStackError: stack level too deep >> >> The position is at the line of Process.waitall. >> >> I have tried to use Process.wait, but this problem still exist. >> >> Any ideas. Thanks. > > But at the heart of your problem is a logic error: you cannot have an > endless loop and wait for all children to exit at the same time. Either > you decide in the main loop that now no more children are to be created > OR you just have a main loop that runs forever - but then there is no > point in waiting for all childs to terminate. > > Kind regards > > robert Hi Robert: Thanks for your replay. > You are doing an unhealthy mix: Process.waitall and wait block to wait > for an event but SIGCLD is supposed to be called when that event > happens. > > So either, use Process.waitall in main or change the trap code to do > something like manipulating a child process counter so you can detect > when the last is gone. > Sorry. I am not sure what do you mean. In my code, it trap the CLD signal to run wait method to clean the zombie sub-process, which is same as the sample code in book 'Programming ruby'. When a child process dies, a signal, SIGCHLD (or SIGCLD) is sent to its parent process. So when I run Process.wait, I always should get the response at once. And this code can work. The only problem is sometimes SystemStackError was raised. Can you please use sample code to show me where is the problem? Thanks. -- Posted via http://www.ruby-forum.com/.