Daemon


(Vivek Nallur) #1

How do I make a script run as a deamon in ruby? I’m trying to create a
variation on fetchmail and hence I want it to run in daemon mode, when
invoked by root or so ‘optioned’

regs
Vivek

···


(Kirk Haines) #2

How do I make a script run as a deamon in ruby? I’m trying to create a
variation on fetchmail and hence I want it to run in daemon mode, when
invoked by root or so ‘optioned’

Here’s one way:

def startDaemon
if (child_pid = fork)
#I’m the parent. Do whatever a parent might do, such as store the
#PID in a file or report it to STDOUT so that something else can
#capture the info and store it.
puts "PID #{child_pid}"
exit
end

#Now, I am the child. I want to be free of my parent.
Process.setsid
end

Call startDaemon(), and when it returns, it will be the daemonized child
process that returns.

Kirk Haines


(Vivek Nallur) #3

Many thanks.

regs
Vivek

···

On Fri, 14 Jun 2002, Kirk Haines wrote:

How do I make a script run as a deamon in ruby? I’m trying to create a
variation on fetchmail and hence I want it to run in daemon mode, when
invoked by root or so ‘optioned’

Here’s one way:

def startDaemon
if (child_pid = fork)
#I’m the parent. Do whatever a parent might do, such as store the
#PID in a file or report it to STDOUT so that something else can
#capture the info and store it.
puts "PID #{child_pid}"
exit
end

#Now, I am the child. I want to be free of my parent.
Process.setsid
end

Call startDaemon(), and when it returns, it will be the daemonized child
process that returns.

Kirk Haines

And on the Seventh day, God turned off his Macintosh