Re: fork not working?
Mike Sassak <[email protected]> Tue, 11 Jan 2005 01:08:20 -0500
| Newsgroups | gmane.comp.apache.mod-ruby |
|---|---|
| Message-ID | <[email protected]> |
The line "p Process.fork do" does not behave as you expect because do has a low precedence. This makes ruby behave as if you had written: p(Process.fork) do `touch /tmp/bar` end which makes a new process without the associated block, when what you meant was: p(Process.fork do `touch /tmp/bar` end) Yuck and yuck, but the script returns, and you don't see an error code. You could use braces instead of do...end or do something like id = Process.fork do <code> end puts id Though having said all that, I must ask why you want to fork a new ruby interpreter from within Apache. :) -mike On Sun, 09 Jan 2005 20:51:29 -0500, Colin Steele <[email protected]> wrote: > Hi, all. I'm running the following mod_ruby script: > > p Apache.server_version > p ENV["MOD_RUBY"] > > `touch /tmp/foo` > > p Process.fork do > `touch /tmp/bar` > end > > sleep 10 > puts `ls -l /tmp/foo` > puts `ls -l /tmp/bar` > exit > > Which produces the following output in my browser: > > "Apache/2.0.51 (Fedora)" > "mod_ruby/1.2.4" > 4474 > -rw-r--r-- 1 apache apache 0 Jan 9 20:44 /tmp/foo > > So I'm left wondering, where'd my forked child with pid 4474 go? What's it doing? How come it didn't touch /tmp/bar? > > Is this a bug or a feature? I grepped around in the mod_ruby source and couldn't find anything obviously related to Process.fork... any help would be greatly appreciated. > > --Colin Steele > [email protected] > >