iperf bandwidth testing woes – killing cleanly etc.

When running iperf on Windows platforms it is difficult to shut it down cleanly, without leaving stray child processes – especially if using within Java using ProcessBuilder.

The solution I’ve discovered takes two approaches. Firstly run iperf server using the lesser known -P 1 switch, this causes it to shutdown after the client has connected.

The second issue is stray processes left. It seems that ProcessBuilder.terminate() and ProcessBuilder.terminateForcibly() won’t kill child processes. The way to do it is to send a SIGINT, i.e. a -2 or Ctrl-C in Linux. Unfortunately Windows + Java doesn’t allow such niceties. Fortunately there is an amazing Third Party library called Sigar which will save the day. This keeps your code platform independent.

Sigar sigar = new Sigar();
sigar.kill(12345, "SIGINT");

Leave a comment

Your email address will not be published.