in reply to Kill a child nicely

Here's another suggestion - no fork, no signals.
Works on my Linux system - I don't have a Windows system to test on...

#!/usr/bin/perl use strict; # https://www.perlmonks.org/?node_id=11154445 use warnings; use IO::Socket; use IO::Select; my $port = shift // 3333; # FIXME my $listen = IO::Socket::INET->new( LocalPort => $port, Listen => 100, ReusePort => 1,) or die $&; my $sel = IO::Select->new( $listen, *STDIN ); print "Hit <ENTER> to quit\n"; for( my $more = 1; $more; ) { for my $handle ( $sel->can_read ) { if( $handle eq *STDIN ) { $more = 0; print "operator wants me to go away\n"; } else { my $live_socket = $listen->accept; while( <$live_socket> ) { # process stuff here print "GOT: $_"; /^\r?\n\z/ and shutdown $live_socket, 1; # NOTE because testin +g with GET } close $live_socket; } } }

Replies are listed 'Best First'.
Re^2: Kill a child nicely
by afoken (Chancellor) on Sep 16, 2023 at 22:11 UTC
    my $sel = IO::Select->new( $listen, *STDIN );

    IO::Select is just an OO wrapper around select, no extra magic added. So all limitiations of select still apply. If you would have read perlport (it is linked from select), you would have found this:

    select

    (Win32, VMS) Only implemented on sockets.

    (RISC OS) Only reliable on sockets.

    Note that the select FILEHANDLE form is generally portable.

    So no, it won't work on Windows, because STDIN is not a socket in your code.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)