in reply to A question of fork efficiency
Here is my go, I like this blog entry about arguments in functions: https://www.matheus.ro/2018/01/29/clean-code-avoid-many-arguments-functions/
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use IO::Socket::INET; sub portCheck { my ($server,$port) = @_; my $sock = IO::Socket::INET->new( PeerAddr => $server, Timeout => 1, PeerPort => $port, Proto => 'tcp', ) || return 0; return 1; } my @checks = ( [ 'perlmonks.com',80 ], [ 'perlmonks.org',80 ], [ 'perlmonks.org',25], ); my @kids; for (@checks) { my $pid = fork // die; if ($pid) { push @kids,$pid; next; } exit portCheck(@$_); } for (0..$#kids) { print "@{$checks[$_]}\n"; waitpid($kids[$_],0); print $? >> 8 ,"\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A question of fork efficiency
by synless (Acolyte) on Aug 06, 2019 at 14:02 UTC | |
|
Re^2: A question of fork efficiency
by synless (Acolyte) on Aug 06, 2019 at 19:01 UTC |