safe way to kill processes?

23 views
Skip to first unread message

William Burke

unread,
Mar 10, 2023, 8:18:14 AM3/10/23
to Quarkus Development mailing list
I'm starting a process using ProcessBuilder in an integration test.  The problem is that the process is a script that spawns child processes and Process.destroy(Forcibly) does not kill child processes.

To get around this I'm using "pkill" and "taskkill", but this scares the shit out of me.

if (System.getProperty("os.name").startsWith("Windows")) {
    Runtime.getRuntime().exec("taskkill /t /f /pid " + process.pid());
} else {
    Runtime.getRuntime().exec("pkill -INT -P " + process.pid());
}

Bad idea??

This code will be a part of azure functions extension support for @QuarkusIntegrationTest

--
Bill Burke
Red Hat

George Gastaldi

unread,
Mar 10, 2023, 8:21:28 AM3/10/23
to bbu...@redhat.com, Quarkus Development mailing list
That seems alright I guess. I’d recommend using https://github.com/zeroturnaround/zt-process-killer but that uses JNA and it may not work well with Native

Best Regards,


George Gastaldi

Principal Software Engineer

Red Hat



--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CAL%3DE%3DjTei5TqEq%2BiEcOHRC18c74KjL5rMLMY1q1W-%2B4yWU65Uw%40mail.gmail.com.

George Gastaldi

unread,
Mar 10, 2023, 8:24:01 AM3/10/23
to bbu...@redhat.com, Quarkus Development mailing list
Just saw that the scope of that project is also to not stop children processes (https://github.com/zeroturnaround/zt-process-killer/tree/master#motivation), so ignore my suggestion.

David Lloyd

unread,
Mar 10, 2023, 9:40:44 AM3/10/23
to bbu...@redhat.com, Quarkus Development mailing list
On Fri, Mar 10, 2023 at 7:18 AM William Burke <bbu...@redhat.com> wrote:
I'm starting a process using ProcessBuilder in an integration test.  The problem is that the process is a script that spawns child processes and Process.destroy(Forcibly) does not kill child processes.

Have you tried something like this (off the top of my head so might be not 100% right):

   process.toHandle().descendants().forEach(destroy());

This should work on any platform, but you might have to tinker with it a little...


--
- DML • he/him

William Burke

unread,
Mar 10, 2023, 10:54:42 AM3/10/23
to David Lloyd, Quarkus Development mailing list
Thanks DML...should have figured that out for myself :(

Max Rydahl Andersen

unread,
Mar 10, 2023, 6:47:48 PM3/10/23
to William Burke, David Lloyd, Quarkus Development mailing list

interesting - did not know that would work reliably on Windows?

/max

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.

David Lloyd

unread,
Mar 10, 2023, 6:55:42 PM3/10/23
to Max Rydahl Andersen, William Burke, Quarkus Development mailing list
I'm not a Windows user but at least from reading the JDK code, I see no reason why it wouldn't at least attempt to do *something* on Windows.

You might have to do something tricky though like collect it to a `List` before you start destroying them to avoid races. Or maybe collect them to ` List`, then destroy in parent-first order, and then forcibly destroy in child-first order. Or something like that.
--
- DML • he/him

Max Rydahl Andersen

unread,
Mar 10, 2023, 6:58:44 PM3/10/23
to David Lloyd, William Burke, Quarkus Development mailing list

My biggest battle been when processes launched via a cmd/bat etc. then it at least
seem like that script can be waiting on output from a process it launched but
its not a true child and thus gets to be a live zombie if you force-stop the script.

Guess no better way than to test it :)

/max
https://xam.dk/about

Jean-Francois Maury

unread,
Mar 13, 2023, 11:07:49 AM3/13/23
to mand...@redhat.com, David Lloyd, William Burke, Quarkus Development mailing list
On JBoss Tools Quarkus integration, we launched quarkus:dev through the Maven or Gradle tooling and the only way to kill the whole process tree was to use taskkill on Windows.



--

Jeff Maury

Manager, DevTools

Red Hat EMEA

jma...@redhat.com   

Reply all
Reply to author
Forward
0 new messages