programming-examples/perl/Network/Forking Servers.pl

16 lines
412 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/bin/perl
use warnings;
use IO::Socket;
my $servsock = IO::Socket::INET->new( Listen => 5,LocalPort => 5000);
sub reap {
wait();
$SIG{CHLD} = \&reap;
} # catch and handle children dying
$SIG{CHLD} = \&reap;
while($client = $servsock->accept()) {
if ($pid = fork()) {
close $servsock;
} else {
close $client; #let the child deal with the client socket
}
}