kaldor has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I don't understand why the following code leaves a zombie process when it's interrupted by CTRL-C (SIGINT) on Windows.
my $cmd = "tail -f $0"; open(my $fh, "$cmd |") or die "cannot open pipe: $!"; while (<$fh>) { print; }

Since the child process is properly killed when run on MacOS, I think it's a Windows specific issue (related to not-being-posix and having different signals/process/fork). An explanation would be welcome.

Then, how should I fix it? By trapping signal(s) and killing it manually?

Thanks.

Replies are listed 'Best First'.
Re: Zombie process after open pipe and SIGINT on Windows
by karlgoethebier (Abbot) on Jan 15, 2023 at 22:42 UTC

    Inquisitorial question: What does open return? Normally this should be the PID of the subprocess in this case – if you had success. By the way, I think you need this (because there is no tail under Windows):

    Get-Content [-ReadCount <Int64>] [-TotalCount <Int64>] [-Tail <Int32>] [-Path] <String[]> [-Filter <String>] [-Include <String[]>] [-Exclude <String[]>] [-Force] [-Credential <PSCredential>] [-Delimiter <String>] [-Wait] [-Raw] [-Encoding <Encoding>] [-AsByteStream] [-Stream <String>] [<CommonParameters>]

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      'open' returns the PID, as it should.
      I'm actually using 'tail' from busybox-w32 for this test.
Re: Zombie process after open pipe and SIGINT on Windows
by kcott (Archbishop) on Jan 15, 2023 at 15:09 UTC
      Hi,
      Actually, my real code executes a long Powershell command that searches stuff.
      I've replaced it by busybox-w32 running as 'tail' to be sure the problem didn't come from this command.
      Result : same behaviour in both cases...
Re: Zombie process after open pipe and SIGINT on Windows
by Anonymous Monk on Jan 15, 2023 at 13:55 UTC
    Windows has an api for that. Mutex job batch process group something. win32 job
Re: Zombie process after open pipe and SIGINT on Windows
by kaldor (Beadle) on Jan 15, 2023 at 10:57 UTC
    Does anybody has a small hint and/or advice?
      Does anybody has a small hint and/or advice?

      To state the obvious, not yet. Otherwise you would have gotten answers by now.

      Windows is not Unix. MacOS X, on the other Hand, inherits more than just the "X" from Unix.

      Windows has no signals, there are no SIGINT, SIGPIPE or SIGCHLD on Windows. Perl has a thin emulation layer, but it is far from being a perfect Unix emulation. See also Re: Handling killing the perl process, Re: Signals in Strawberry Perl: Name or number?, perlport, perlwin32.

      Alexander

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

        Sorry for being rude. I dared ask again because I've initially posted between Christmas and New Year.

        Thanks for the links. I've read and investigated quite a lot before posting here and, to be honest, I don't fully understand everything. That's the reason why I'm asking a question.

        Having this child process running is obviously not satisfactory, but I still haven't found any information on how to handle such a situation... What would a software consultant from BigCorporation do? Close eyes and call it a day?