From: Bedo Sandor Date: 2003-10-17T16:46:30+09:00 Subject: Re: Thread + fork warning On Wed, Oct 15, 2003 at 11:16:43PM +0900, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Thread + fork warning" > on 03/10/15, Bedo Sandor writes: > > |% chmod +x thread.rb ; ./thread.rb > |./thread.rb:4: warning: fork terminates thread at ./thread.rb:8 > | > > When you fork, all other threads are terminated in the child process. But only in the child process!? This is exactly what I want! In my program the main process forks&execs other processes, and in the main process creates a thread to wait/waitpid the forked process, and log the time and the pid when done. I don't need thread in the Ruby interpreter in the child processes, they only execs an external command. I think the correct behavior would be in a threaded Ruby program that fork does not harm threads in the main process, but starts an other interpreter without threads running only with the commands in the block passed to the Kernel.fork. > The simplest solution is not mixing fork and threads, for example, use > system instead of fork+exec. I have two problems with system(): - I can't log the termination of the spawned process. - Don't know if this is a correct way to start background processes: (I need background processes, so I have to continue the main Ruby program!) def startInBg(unixCommand) system(unixCommand.to_s + "&") end ... startInBg 'zcat /var/log/messages*.gz | logClassifier' It works, and there's no warnin, but what do You think about +"&" ? -- bSanyI