Nevermind, it does work! =20
My test application was the following Ruby application:
#!/bin/env ruby
while true
puts "pid: #{Process.pid}, time: #{Time.now}"
sleep 0.2
puts=20
end
Does #puts not write to STDOUT by default?
On 6/27/05,
<> wrote:
>=20
> On Jun 27, 2005, at 1:37 PM, Joe Van Dyk wrote:
> > Why doesn't this work?
>=20
> Disclaimer: I'm pretty good with Unix System stuff
> but still learning on the Ruby so...
>=20
> > (#executable is a function that returns a string that contains a test
> > application that spits out some data)
> >
> > def start
> > pid =3D fork
> > if pid.nil? # In child
> > log =3D File.open(executable + ".log", "w")
> > STDOUT.reopen(log)
> > STDERR.reopen(log)
> > exec executable # Start program
> > exit
> > else # In parent
> > @pid =3D pid # Record new process id
> > Process.detach @pid # If the process dies, let it die
> > monitor # Start monitoring the process' status
> > end
> > end
>=20
> This worked for me (Mac OS X 10.4, Ruby 1.8.2). Check the permissions
> on the log file. If was created in earlier tests as a read-only file
> maybe
> that is why the program fails now.
>=20
> If you have something like ktrace or truss on your system, trace
> the ruby program and then look at the dump. You can see exactly
> what system calls are being made (open/read/write/etc) and also
> what errors, if any, are being returned.
>=20
> Try using some standard program such as /bin/date instead of executable
> just to make sure it isn't a problem with your test program. You'll
> probably want a different path for the log file in that case.
>=20
> If 'monitor' is going to watch the child process then just incorporate
> calls to Process.wait(@pid) as part of 'monitor' instead of
> Process.detach. If you have both Process.detach and monitor
> periodically
> calling Process.wait, you'll never be sure which thread is going to
> catch the exiting child.
>=20
>=20
>=20
> Gary Wright
>=20
>=20
>