in reply to How to portably stop processes?

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: How to portably stop processes?
by haj (Vicar) on Mar 31, 2023 at 19:09 UTC

    No, and no.

    First, obvious from my text: I asked for a portable way. A command which only works on Windows doesn't help.

    Second, not obvious from my text: My program spawns several processes, all using the same program name, all running simultaneously. I need control which of them I terminate, and the filter offered by taskkill is insufficient to distinguish between these.

      > My program spawns several processes

      Correction: it spawns several pseudo-processes on windows which are all emulated inside the main process.

      That's also why taskkill can't work, the $child_id you get from fork is meaningless for the OS.

      https://perldoc.perl.org/perlfork#SYNOPSIS

      On some platforms such as Windows where the fork() system call is not available, Perl can be built to emulate fork() at the interpreter level. While the emulation is designed to be as compatible as possible with the real fork() at the level of the Perl program, there are certain important differences that stem from the fact that all the pseudo child "processes" created this way live in the same real process as far as the operating system is concerned.

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: How to portably stop processes?
by LanX (Saint) on Mar 31, 2023 at 17:03 UTC
    The OP wrote

    > The PID returned from fork is apparently useless. When I kill 1 $child_pid, the main process complains Terminating

    Did you test your "solution" against his setting?

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

    A reply falls below the community's threshold of quality. You may see it by logging in.