O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting ready

Let's create a simple shell script, which we will be using in the recipe. This script can be found at chp8/11_managing_sub_process/script.sh:

echo "Running tree command";
tree;
sleep 60;
echo "Running iostat command";
iostat;

In the preceding script, we are running the commands, tree and iostat, separated by a sleep time of 1 minute. If you want to know about these commands, please refer to the Running shell scripts recipe of this chapter. The sleep command, when executed from within the bash shell, creates a new subprocess each time it is invoked.

We will create, say, 10 instances of ProcessBuilder to run the preceding shell script and launch them simultaneously.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required