@Test
    public void testProcessForceKillTimeout() throws Exception {
        if (OperatingSystem.IS_WINDOWS) return;
        File tempFile = null;
        try {
            tempFile = TestUtils.tempFile();
            try (OutputStream stream = Files.newOutputStream(tempFile.toPath())) {
                for (String line : new String[] {
                    "echo hello world\n",
                    "# Test that the initial message is sent correctly.\n",
                    "read -r line\n",
                    "[[ $line == '{\"id\":\"testForceKillTask\",\"workload\":{\"foo\":\"value1\",\"bar\":123}}' ]] || exit 0\n",
                    "\n",
                    "# Ignore SIGTERM signals.  This ensures that we test SIGKILL delivery.\n",
                    "trap 'echo SIGTERM' SIGTERM\n",
                    "\n",
                    "# Update the process status.  This will also unblock the junit test.\n",
                    "# It is important that we do this after we disabled SIGTERM, to ensure\n",
                    "# that we are testing SIGKILL.\n",
                    "echo '{\"status\": \"green\", \"log\": \"my log message.\"}'\n",
                    "\n",
                    "# Wait for the SIGKILL.\n",
                    "while true; do sleep 0.01; done\n"}) {
                    stream.write(line.getBytes(StandardCharsets.UTF_8));
                }
            }
            CompletableFuture<String> statusFuture = new CompletableFuture<>();
            final WorkerStatusTracker statusTracker = status -> statusFuture .complete(status.textValue());
            ExternalCommandWorker worker = new ExternalCommandWorkerBuilder("testForceKillTask").
                shutdownGracePeriodMs(1).
                command("bash", tempFile.getAbsolutePath()).
                build();
            KafkaFutureImpl<String> doneFuture = new KafkaFutureImpl<>();
            worker.start(null, statusTracker, doneFuture);
            assertEquals("green", statusFuture.get());
            worker.stop(null);
            assertTrue(doneFuture.get().startsWith("exited with return code "));
        } finally {
            if (tempFile != null) {
                Files.delete(tempFile.toPath());
            }
        }
    }
Test running a process which needs to be force-killed.
trogdor/src/test/java/org/apache/kafka/trogdor/workload/ExternalCommandWorkerTest.java