mikealeonetti has asked for the wisdom of the Perl Monks concerning the following question:

The program I'm writing forks off a daemon process which I'd like to be able to communicate with to get it to do things via the command line controller.

Doing research on Perl IPC, I'm guessing the best way to communicate with it would be on a named pipe but the daemon can't be blocked spending all it's time waiting for somebody to give it a command because it has other daemonly things to do (it has to watch RSS feeds).

What's the best way to get it to receive commands (like reload config, e-mail report, etc) but not stop it from checking for RSS updates?

Or am I once again thinking about this all wrong?

Thanksss.

  • Comment on Sending commands to another process that isn't expecting it

Replies are listed 'Best First'.
Re: Sending commands to another process that isn't expecting it
by mellon85 (Monk) on Dec 05, 2010 at 09:43 UTC
    As you are forking the process you can keep track of the PID of the children and use signals to tell the child to wait for a message in the pipe using the function kill

      The process issuing the commands to the daemon will not be a parent of the daemon.

      Should I just send a SIGUSR1 to the daemon process using kill and then in the handler for SIGUSR1 in the daemon have it check a fifo file for input?

        That's exactly what I meant
      That uh... Anonymous response was actually from me. I didn't see that I wasn't logged in... Embarrassingly enough.
Re: Sending commands to another process that isn't expecting it
by salva (Canon) on Dec 05, 2010 at 10:41 UTC
    Or am I once again thinking about this all wrong?
    Even without knowing the full details or your project it looks as it could be better implemented using POE or some other event based framework.
      There is a separate daemon running that is checking every x minutes for RSS updates. That daemon needs to be commanded by a separate process that will tell it to do certain things. I'm just curious what the best way may be to have the daemon continue to check for RSS updates but still be able to process commands. And basically the best way to get those commands to the daemon to process.
        The classical answer is a select loop. POE is a framework to do a select loop. Basically, a select loop means, you have three (possible empty) sets of filehandles: handles you want to read from, handles you want to write to, handles you're watching for errors. Using a select call (4 arg select, for details, see the manual page), you wait until "something" happens: one or more of the handles you are waiting on comes available, or a timeout happens. So, you use one of the handles to read from your pipe (or stdin), and the other handles to read your RSS feed. Do whatever is appropriate when a handle becomes available.

        Personally, for simple things, I use 4-arg select. For more complicated things, I'd use POE. (Note that POE isn't the only framework available).