Re: Multiple Daemons - same script?
by rev_1318 (Chaplain) on Jul 21, 2005 at 14:19 UTC
|
What have you tried so far? Can you show us some sample code?
Essentially, it could be reolved with multiple forks, as in following (speudo) code: if (fork) {
exec "daemon1"
}
if (fork) {
exec "daemon2"
}
| [reply] [d/l] |
Re: Multiple daemons in one script?
by jdhedden (Deacon) on Jul 21, 2005 at 14:38 UTC
|
| [reply] |
Re: Multiple daemons in one script?
by ikegami (Patriarch) on Jul 21, 2005 at 14:32 UTC
|
I think you can use select RBITS,WBITS,EBITS,TIMEOUT on the server sockets then call accept on the one that returns. Sorry, I don't have time to elaborate or to try this at the moment.
| [reply] [d/l] [select] |
Re: Multiple Daemons - same script?
by pbeckingham (Parson) on Jul 21, 2005 at 15:56 UTC
|
Please consider a routine shutdown/restart of your daemon. As with any daemon, let alone one written in Perl, it is imperative that there be no memory leaks, and given the difficulty in achieving this in anything but trivial cases, I suggest an automatic periodic restart.
pbeckingham - typist, perishable vertebrate.
| [reply] |
Re: Multiple daemons in one script?
by Anonymous Monk on Jul 21, 2005 at 14:16 UTC
|
Yes, that's possible. What kind of daemons are they? Do they listen to ports and respond to requests? Do they perform background tasks? You will probably need an event loop of some kind of another.
Having said that, it might be a lot easier to split the code and run two processes. If only by doing an early fork(). | [reply] [d/l] |
Re: Multiple Daemons - same script?
by samizdat (Vicar) on Jul 21, 2005 at 15:04 UTC
|
Daemons, once launched, are always running. Once you have FORKed it, (and gotten the PID as described by the previous poster), you can open socket connections to both and communicate as simultaneously as your OS's scheduler will let you. Both daemons and your original process will remain running until you terminate them; that's the nature of daemons. | [reply] |
Re: Multiple Daemons - same script?
by jdhedden (Deacon) on Jul 21, 2005 at 14:40 UTC
|
| [reply] |
Re: Multiple Daemons - same script?
by kryptonite (Initiate) on Jul 21, 2005 at 17:00 UTC
|
Thanks, all, for the feedback! As I'm fairly new at this, the notion of how daemons work is still somewhat of a black box, and some approaches described here are a little confusing (so you are right, jdhedden!). The daemons will be handling data of different types sent to a single script. Datatype A will be handled by daemon1, Datatype B will be handled by daemon2 and both types are coming from different sources. I am unable to provide code examples since my code rests on a private network, but I'm going to try to implement some form of the suggestions here. I'm sure I'll be back with more questions. Thanks again!
| [reply] |
|
I just recommended this book on another thread, Saving big blessed hashes to disk, and it's even more appropriate here: "Network Programming with Perl" ISBN 0201615711. It goes into detail about preventing memory leaks, long term, with daemons on different platforms and nice ways to encapsulate things and do dispatch stuff.
| [reply] |