Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Multiple consecutive connections to a socket (probably a stupid question)

by vr (Curate)
on Dec 25, 2016 at 16:31 UTC ( [id://1178485]=note: print w/replies, xml ) Need Help??


in reply to Re: Multiple consecutive connections to a socket (probably a stupid question)
in thread Multiple consecutive connections to a socket (probably a stupid question)

Oh, I see, thank you. Can there be negative effects, if I place

1 while waitpid(-1, WNOHANG) > 0;

immediately after the "system(1, ..." line? (I checked, it works. I suppose it marks a still running process to be "reaped automatically")

One more question. Client code catches all errors, and therefore, in theory, it always sends a reply to "server". But, if it does something horrible and Perl interpreter crashes ("out of memory" or similar), can server somehow know about it? Maybe using PID returned by "system(1, ...".

Edit (after reading huck's answer): It looks like my "idea" (where do I get them from? I don't know) about "marking for auto-reaping" is wrong. Then, the above line of code can be placed anywhere in the "server", if it's executed with the same (or more) frequency, as creating "clients". Which maybe means, the good place can be not after, but before calling "system". Number of "clients" is limited in real application.

  • Comment on Re^2: Multiple consecutive connections to a socket (probably a stupid question)
  • Download Code

Replies are listed 'Best First'.
Re^3: Multiple consecutive connections to a socket (probably a stupid question)
by huck (Prior) on Dec 25, 2016 at 19:53 UTC

    While that code will reap anything that is already terminated, it does not insure that system calls terminate faster than they are generated. If the count is already at 64 You need some sort of counter that blocks the next system call from starting before one finishes.

    while there is a return code in $? right after the waitpid i dont think there is any way to capture any textual error when you use system(1,...)

Log In?
Username:
Password:

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

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

    No recent polls found