-2

I have a strange case, we want to collect ping (in linux machine) response, it works well if we specified ping count, however, for those endless ping, in normal case, we will use ctrl + c to stop them, then you will get a summary in linux.

However, I find it is not work if I do it in JAVA side.

My basic idea is start up a process with JAVA, then send a ping www.google.com with this process, after that, I try to send a ctrl+c (\003) to stop this process and get summary info, however, nothing happens after I send ctrl +c

After checking it a little bit, I found before ping command finishes, all of other command will just hold until it finish, so that I dont have any opportunity to close this process, if I do it with destroy, then I will lose the stream info (Summary info)

Thanks in advance.

Br, Tim

Tim
  • 2,006
  • 2
  • 18
  • 25
  • I dont think your suggestion solve my problem, I dont want to capture this ctrl c, what I want to know is if there is a way to send a ctrl+c to my existing java process.pls remove the minus 2 if you dont have better suggestion. – Tim Nov 02 '15 at 20:37
  • I wasn't the one who downvoted you, also, you can only downvote once so there isn't even a way for me to remove both... – user1231232141214124 Nov 02 '15 at 22:20
  • got it, we can just let it go, thanks for your reminder anyway, based on this, I got my answer finally :) – Tim Nov 03 '15 at 09:34

2 Answers2

2

Do you know the PID of the ping process? If so, you could send the SIGQUIT signal to recieve the statistics. Afterwards you could kill the process.

See this post on Unix & Linux Stack Exchange.

Yeti
  • 1,108
  • 19
  • 28
  • Thanks, I will try it tomorrow, just now I just try to send this one "INT" and it works. – Tim Nov 02 '15 at 21:00
  • Thanks, it looks good and similar with my way, I will play this also tomorrow. – Tim Nov 02 '15 at 21:02
0

Finally, I got a answer after a few try, this solve my problem Runtime.getRuntime().exec("kill -s INT -9 -P 5904");

Tim
  • 2,006
  • 2
  • 18
  • 25