in reply to Child process lingers after keyboard interrupt on Windows

I found that fork + exec is the way perl spawns a sub-process, including on Windows. With this the keyboard interrupt will be sent to the subprocess as expected:

my $child = fork(); if ($child) { say 'Waiting'; waitpid $child, 0; say 'Exiting' } else { exec 'cmd', '/C', 'PowerShell', '-Command', 'sleep', '7', '&', 'Echo', 'Done' }
I suppose I still have to disable $SIG{'INT'} while waiting for the subprocess (that is, before the waitpid call), like system() does, but somehow I still want to receive the interrupt after the child process exits.

Replies are listed 'Best First'.
Re^2: Child process lingers after keyboard interrupt on Windows
by afoken (Chancellor) on Nov 01, 2018 at 22:44 UTC
    I found that fork + exec is the way perl spawns a sub-process, including on Windows.

    No. Windows has neither fork() nor exec(). Perl emulates both on Windows, fork() using multiple interpreters (see perlfork), and exec() by starting and supervising a process (that on Unix would replace the current process).

    I suppose I still have to disable $SIG{'INT'} while waiting for the subprocess (that is, before the waitpid call), like system() does, but somehow I still want to receive the interrupt after the child process exits.

    Windows has no signals. Perl emulates signals on Windows.

    Alexander

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