Re: fork not working?

Mike Sassak <[email protected]> Tue, 11 Jan 2005 17:53:13 -0500
Newsgroups gmane.comp.apache.mod-ruby
Message-ID <[email protected]>
I see. Thanks for explaining. :)

On Tue, 11 Jan 2005 14:08:08 -0500, Colin Steele <[email protected]> wrote:
> Errrr.... yuck is right.  I think I must not have had enough coffee when
> I was writing that one up.  Regardless of the poor writeup I did of the
> problem, it appears to be a known issue.  Google helped me find this:
> http://i.loveruby.net/d/20040328.html
> 
> I tried the script on that page and sure enough, looks like the same
> results - the child SEGVs.  :(
> 
> As for why I'd like to fork, well, I have a long-running background
> process that I need to kick off from a mod_ruby script.  It's not
> appropriate as a cron job.  It's also the sort of situation where the
> end user doesn't have access to the system on which the process runs, or
> isn't savvy enough to be asked to log in and start a background job.
> So... I just wanted to start it from a web page.
> 
> --Colin
> 
> On Tue, 2005-01-11 at 01:08, Mike Sassak wrote:
> > 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]
> > >
> > >
> >
> 
>