in reply to Re^2: break thread with system(...) call
in thread break thread with system(...) call

maybe there is a way to follow the process tree or kill cmd.exe in such a way that all children will be also killed?

Yes. Use Win32::CreateProcess and the include CREATE_NEW_PROCESS_GROUP. Use it to start cmd.exe and then supply your complex command line.

When you kill cmd.exe, any child processes it has created will be killed also.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^4: break thread with system(...) call
by BrowserUk (Patriarch) on Jul 17, 2008 at 13:12 UTC

    Some further info on this:

    1. You must use perl's built in kill, with a signal number 21 (SIGBREAK).

      Win32::Process::Kill() only gets the immediate child, not the group.

    2. Only processes that share the same console will be killed.

      That means that if all the processes in your complex commands are simple command line apps, then all children and their grandchildren etc. will be killed as a group.

      But if any of the processes allocate their own console, or do not use a console (eg. notepad.exe), then they will survive. I do not have a simple solution for these.


    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.