On Thu, Oct 04, 2007 at 06:47:25PM +0900, Han Holl wrote:
> This one:
> 
> #!/usr/bin/ruby -w
> trap('TERM') do
>   exit
> end
> 
> IO.popen("tail -F --lines=0 --pid=#{Process.pid} /var/log/messages") do |h|
>   while line = h.gets
>     puts line
>   end
> end
> # end-of-program
> 
> cannot. It hangs on a waitpid (or wait4) for the tail process.
> Why is this ? And is it reasonable ?

Same problem with this program:

$ ruby -v
ruby 1.8.2 (2004-12-22) [i686-linux]
$ ruby -e 'r = IO.popen("tail -f /dev/null"); r.close'
<hangs>

But this one does not:
$ ruby -e 'IO.popen("tail -f /dev/null")'

I see no way to close the fd without waiting on the child process, so if
you want this behavior, don't use popen (you can use Open3.popen3
instead).

Paul