question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Terminate Command

See original GitHub issue

Hi, how can i terminate infinite loop command that run with “execCreateCmd” like ping or any others ? here is my code

ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(ubuntu_container.getId())
                .withAttachStdout(true)
                .withCmd("ping", "google.com")
                .withUser("root")
                .exec();

        dockerClient.execStartCmd(execCreateCmdResponse.getId())
                .exec(new ExecStartResultCallback(System.out, System.err));

it ping google.com infinitely, how can i terminate it(something like ctrl-c) .

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
xbj110825commented, Apr 26, 2021

I found a way to terminate specific process by sending 0x03(control character: end-of-text ^C) to it’s stdin.

DockerClient dockerClient = dockerClient();
String exeId = dockerClient.execCreateCmd("1d87fe71c8bb")
        .withCmd("ping", "127.0.0.1")
        .withAttachStdin(true)
        .withAttachStdout(true)
        .withAttachStderr(true)
        .withTty(true)
        .exec().getId();

PipedInputStream pipedInputStream = new PipedInputStream();
PipedOutputStream pipedOutputStream = new PipedOutputStream();
pipedInputStream.connect(pipedOutputStream);

ResultCallback.Adapter<Frame> execCallback = dockerClient.execStartCmd(exeId).withStdIn(pipedInputStream)
        .exec(new ResultCallback.Adapter<Frame>() {
            @Override
            public void onNext(Frame object) {
                try {
                    System.out.write(object.getPayload());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
        });
Thread.sleep(3000);
pipedOutputStream.write(3);
execCallback.awaitCompletion();

Ping process exits in three second.

PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.054 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.045 ms
^C
--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2010ms
0reactions
stale[bot]commented, Jun 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TERMINATE command - IBM
The TERMINATE command explicitly terminates the back-end process of the command line processor.
Read more >
How to Abort a Command Execution in Command Prompt?
Now Type 'Y' and hit “Enter” to terminate the process. What if say type “N”? The Command will continue to execute if we...
Read more >
how to stop command execution in command prompt windows ...
CTRL+C will send a break (stop execution) when no text is selected. Try it ;-).
Read more >
Procedure How to Terminate a Process ( kill )
When using the kill command to stop a process, first try using the command by itself, without including a signal option. Wait a...
Read more >
TERMINATE Command
Was this helpful? ... The TERMINATE command stops X100 and rolls back any transaction that is in progress. This command has the following...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found