uncutstone
5/13/2006 11:38:00 AM
I made more test of the code and eventually found you are right and got
a clear understanding of it. Yes, the child process never exits and
sends no signal .
It is really tricky and interesting to see the way how the child
process get blocked.
When the code is "34.times do" , the result is:
"child process 577605 exits " was displayed on the screen
and then deadlock happened.
And after I use ctrl -c to break it, I got:
main.rb:2:in `wait': Interrupt
from main.rb:2
It shows that child process get blocked before it exits. It wait the
parent process to read pipe before it exits.
But when I change the code to "68.times do", the result is:
Nothing displayed on the screen and deadlock happens.
And after I use ctrl -c to break it, I got:
main.rb:2:in `wait': Interrupt
from main.rb:2
saygoodbye.rb:3:in `write': Bad file descriptor (Errno::EBADF)
from saygoodbye.rb:3:in `puts'
from saygoodbye.rb:3
from saygoodbye.rb:1:in `times'
from saygoodbye.rb:1
It shows that child process get blocked immediatly when it is doing
pipe writing.
Let me make a simple summary for it:
1. If the child process write too much to pipe, it will get blocked and
doesn't exits , doesn't send exit signal.
2.The way the child process get blocked is depending on how much it
want to write to the pipe.
2.1 If the child process make the pipe full but not too full, it will
get blocked before it exits.
2.1 If the child process make the pipe full and even too full, it will
get blocked immediatly at pipe writing.
Do you agree with it .Very Thanks .