As an alternative, instead of forking, just start all the connection attempts in non-blocking mode, then after the appropriate time, check for connections, sort of like this:

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11146781 use warnings; use Path::Tiny; use IO::Socket; my $port = 3143; # FIXME to my https://rosettacode.org/wiki/Hunt_the_W +umpus#Perl my @ips = map "192.168.1.$_:$port", 10 .. 20; # FIXME for testing my $logfile = path( "/tmp/d.11146781,log" ); # FIXME filename my $timeoutin = 0.1; # FIXME short for testin +g my $log = localtime() . " begin\n"; my %sockets; $sockets{ $_ } = IO::Socket::INET->new( PeerAddr => $_, Blocking => 0 ) or $log .= "$_ fail $@\n", next for @ips; # start all connections select undef, undef, undef, $timeoutin; # the time allowed $log .= "$_ " . ( $sockets{$_}->connected ? "ok\n" : "failed\n" ) for grep $sockets{$_}, @ips; $logfile->spew( $log, localtime() . " end\n" ); print $logfile->slurp; # FIXME for testing #rename here...

Which on my machine outputs:

Tue Sep 13 10:26:54 2022 begin 192.168.1.10:3143 failed 192.168.1.11:3143 failed 192.168.1.12:3143 ok 192.168.1.13:3143 ok 192.168.1.14:3143 failed 192.168.1.15:3143 ok 192.168.1.16:3143 failed 192.168.1.17:3143 failed 192.168.1.18:3143 failed 192.168.1.19:3143 failed 192.168.1.20:3143 failed Tue Sep 13 10:26:54 2022 end

No forks, no 'wait's, no 'alarm's, no 'flock's and the system does all the concurrency for you :)


In reply to Re: Multiprocess - child process cannot be finished successfully by tybalt89
in thread Multiprocess - child process cannot be finished successfully by wonderG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.