in reply to Killing on Windows

You're being told the process still exists, which it will until all handles to it have been closed. In unix parlance, the child is zombie at that point. Processes exist in that state in order to allow their parent to collect their exit code. wait and waitpid collect the exit code and close the handle.

my $pid = system(1, $^X, -e => 'sleep 30 while 1') or die("system,1: $!\n"); kill(9, $pid) or die("kill: $!\n"); if (kill(0, $pid)) { print("Process $pid still exists\n") ; } else { print("kill 0: $!\n") ; } waitpid($pid, 0) or die("waitpid: $!\n"); if (kill(0, $pid)) { print("Process $pid still exists\n") ; } else { print("kill 0: $!\n") ; }
Process 4912 still exists kill 0: Invalid argument

Replies are listed 'Best First'.
Re^2: Killing on Windows
by rovf (Priest) on Sep 10, 2009 at 08:00 UTC

    Thanks for the explanation. I now see that my real problem is that the kill of course kill only the process directly invoked; but that process had at this time already invoked other child processes, and *they* are of course not killed, and they run to the end.

    What possibilities exist in Windows to kill a process *including* all of its children in one go? On Solaris, I would use pkill. I think this is such a common problem that there is likely also something available for Windows...

    -- 
    Ronald Fischer <ynnor@mm.st>
      What possibilities exist in Windows to kill a process *including* all of its children in one go?

      See Win32::Job.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Yes, this is a possibility indeed. I just was curious whether there is a possibility to kill jobs started with system(1,...); sorry if I was not clear enough in this respect.

        It turns out that at least with my tests, I did find a solution which seems to work: Using a negative kill signal (kill -9) killed also my children. Knowing that Windows gets funny at times, I wonder whether this is indeed a reliable solution, or whether there could be cases when this strategy fails to work.
        -- 
        Ronald Fischer <ynnor@mm.st>