Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: forking in Tk and letting the dad alone deal with X stuff

by {NULE} (Hermit)
on May 16, 2002 at 13:43 UTC ( [id://167009]=note: print w/replies, xml ) Need Help??


in reply to Re: forking in Tk and letting the dad alone deal with X stuff
in thread forking in Tk and letting the dad alone deal with X stuff

Update: I changed my mind on this - see my newest node at the end of the discussion.

Hey stefp,

Thanks for the example. I'm afraid I don't agree that the parent/child relationship can't be changed. I think in your shoes I would still be thinking about handling this with a pre-forked process. Or I would be trying to avoid the complexity of the parent/child as it is not clear to me the value that it provides.

I am probably going to butt out now, because without a better idea of why you cannot or are not willing to change the archetecture I can't be of much help. Would I be correct in thinking that this fork only happens once at the beginning of the process? I'm not saying you are wrong and you very well may be doing this the best way possible and if so I hope you can easily resolve your issues with the help of the monastery.

But before I butt out, let me ramble aimlessly for a bit. {g} If you must fork there are a few reasons why pre-forking a child strikes me as a good idea. First is it reduces process management issues. In your example you have no wait or waitpid which will eventually lead this process to fail if it is in a loop. With a single pre-forked child you can simple ask the child to exit and wait once at the end. It also makes signal handling less difficult (or perhaps just less critical).

If you are going to pre-fork, that child could just listen for a message from the parent saying "Get me this $file", and then the child reacts to that an passes the information pback over the socket pair and listen again for the next directive. It's different than what you are doing in your example, but depending upon what you are trying to accomplish it may be a cleaner way to do it.

Second, inheriting things like the Tk objects is obviously avoided if you pre-fork. This provides a savings in memory and in start-up time, particularly if the forking happens repeatedly. In an interactive program this may not be much of an issue since people are used to waiting for the hourglass so to speak.

Next, if the child isn't doing some tremendous value add stuff, forking at all doesn't seem to be helpful in this case (in fact it adds much complexity). The reason I see to fork is to better handle blocking issues but with a filehandle there are any number of ways in this issue in this. Using IO::Select on your filehandle in a loop lets you do processing and prevent blocking during your read process.

Well, anyway I wish you luck. If I think of anything helpful to add (as opposed to my babbling just now. :) ) I'll check back in.
{NULE}
--
http://www.nule.org

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://167009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-03-28 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found