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

http://perldoc.perl.org/perlport.html#system "system(1, @args) spawns an external process and immediately returns its process designator, without waiting for it to terminate. Return value may be used subsequently in wait or waitpid."

You need to "wait or waitpid" these processes. Win has a limit of 64 outstanding. Also Re: Win32 limit to number of calls to system()?

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

Replies are listed 'Best First'.
Re^2: Multiple consecutive connections to a socket (probably a stupid question)
by vr (Curate) on Dec 25, 2016 at 16:31 UTC

    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.

      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,...)