Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Need Help with Sockets, Please

by ferrency (Deacon)
on May 09, 2002 at 14:19 UTC ( [id://165380]=note: print w/replies, xml ) Need Help??


in reply to Need Help with Sockets, Please

The code you wrote looks to me like it'll work only as long as the connection created in your IO::Socket::INET command stays up. If a network outage occurs, if the remote end closes the connection, or if the person or script sending input to your script via STDIN closes the pipe, then one of your while() loops will finish and the corresponding process will die.

Also: as it is now, if your child dies (remote connection close) but your STDIN keeps coming, the parent process will live on indefinitely, but it won't work very well.

You could try to wrap the entire thing in a while (1) loop, but that wouldn't fix the problem of one process living on once the other exits. One way to fix this is to make sure the parent process is the one which exits its loop most often, and then to have it kill off its child process after the loop exits, since it knows its child's pid.

Without seeing what you're doing in the while loops it's hard to tell whether this is the best way to do what you want. Be aware that after you fork(), you can't share new variable values between the parent and child processes. Your idea to share data through files can work, but beware of deadlock.

Alan

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-24 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found