in reply to Re: Fork daemon from Perl script and save it's PID. How to do it right?
in thread Fork daemon from Perl script and save it's PID. How to do it right?

I think about communication too. But there is no way to change behaviour of child. Actually I'm trying to fork DHCP daemon provided with SUSE10. Of course I can rewrite and recompile it but I have to support default binary and be able to provide my Perl script to any user of SUSE10 and it must work. Is there any way to handle starting/stopping of standard system daemons?
  • Comment on Re^2: Fork daemon from Perl script and save it's PID. How to do it right?

Replies are listed 'Best First'.
Re^3: Fork daemon from Perl script and save it's PID. How to do it right?
by moritz (Cardinal) on Nov 26, 2008 at 10:22 UTC
    Is there any way to handle starting/stopping of standard system daemons?
    On Debian that's simply /etc/init.d/daemonname start|stop, I'm sure that suse offers a similar way.

    A more low-level approach is to use start-stop-daemon directly.

      Yes, I know. I do exec() on daemon binary directly. But problem is that daemon binary inside itself have something like "fork() && exit()" which allow it to be a daemon. Side effect is that new PID is allocated to forked process.And PID saved in Perl script become useless trash. Is it clear enough?
        Yes, I know. I do exec() on daemon binary directly.
        And that's the problem. If you just use the init scripts both for starting and stopping the daemon, you don't have to care about all this stuff. That's what the init scripts are for.
        Is it clear enough?
        Yes, the difficulties with your current approach are clear to me. But I don't see why you have to take this approach. When you ask how to start and stop daemons, I tell you how it's usually done. Why can't you use the daemon in a way that the standard techniques apply?