in reply to How do I run a script in the background? How should I run a script as daemon?

If you run a script in a the background with exec, things go nasty after a while when you kill your terminal. You can prevent this (I tried it only under linux) by setting SIG{INT}='IGNORE'.

Actually, a better solution is the Proc::daemon module, or the Net::daemon module if you need to claim a socket.

Replies are listed 'Best First'.
Re: Answer: How do I run a script in the background? How should I run a script as daemon?
by Fastolfe (Vicar) on Nov 22, 2000 at 18:36 UTC
    It's not the INT signal you need to worry about, but the HUP signal. This can also be averted by disassociating the new process from the old one (which also disassociates it from the controlling terminal, preventing things like the HUP broadcast from reaching it) by using POSIX's setsid function. I believe perlipc gives a good example of a "daemonize" function that does a good job of setting up a child process in such a way that it is completely disassociated from its parent.