From: James Gray Date: 2009-04-25T04:17:54+09:00 Subject: Re: proper way to daemonize On Apr 24, 2009, at 11:40 AM, Gary Wright wrote: > > On Apr 24, 2009, at 12:11 PM, James Gray wrote: > >> On Apr 24, 2009, at 11:01 AM, Gary Wright wrote: >> >>> On Apr 24, 2009, at 11:11 AM, Tim Pease wrote: >> >>> >>>> This is the standard code to daemonize a process. The use of "exit" >>>> bothers me slightly, as it will call all "at_exit" handlers in the >>>> parent. I do not believe this is the desired behavior; the >>>> "at_exit" >>>> handlers will free resources that the daemonized process might >>>> need. >>> >>> What resources are you talking about? By the time exit is called, >>> the >>> process has already been duplicated. The child process won't be >>> affected >>> by anything the parent does during via at_exit processing (at least >>> with respect to Ruby object resources). >> >> But if that at_exit() handler deletes a file or something… > > > Well, that is why I put the caveat about 'Ruby object resources'. > Isn't it fair to assume the at_exit code isn't actively hostile? :-) > > If you've got at_exit() code that is trashing external resources > that are used by a child process, that is a bug to be fixed I think > rather than a bug to be obscured via exit! Seems like Tim has a pretty decent example where the behavior doesn't feel buggy. Basically, I view it this way. The exit() calls in a daemonize() method aren't the typical usage. Normally, exit() is used to end a process. Our process isn't really ending though so much as transitioning into a different kind of process. exit() is just an implementation detail of how that transition occurs. As such, exit!() feels more correct to me because I don't want to go through a shutdown sequence of the original process, I just want the first to immediately cease to exist while the second takes over for it. That's all just my opinion though. Feel free to ignore. James Edward Gray II