in reply to Re^2: 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?

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.

Replies are listed 'Best First'.
Re^4: Fork daemon from Perl script and save it's PID. How to do it right?
by accessdenied (Acolyte) on Nov 26, 2008 at 10:44 UTC
    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?
        Does init scripts return PID? I don't think so. They doesn't operate with PID even. Well, DHCP is not good example. Between others I have to start several instances of another daemon. Doesn't mater which one. It's source code can't be fixed too. It has the same "fork && exit" pair inside. And the same "wrong saved PID" problem too. Init scripts allow start one instance and I need several. Also I need to save PID to select which instance to stop on request. Standard approach doesn't work here, as I think. Do you have any more suggestions?