1

So I have a jar file that I need to run five times with a ./run.sh script.

So I put the jar fle back to back in the script 5 times.

#!/bin/bash
java -jar lol.jar
java -jar lol.jar
java -jar lol.jar
java -jar lol.jar
java -jar lol.jar

And it didn't work. The java files launch one after the other when I terminate the previous.

So how do I run 5 instances of the same jar at the same time?

I was thinking I could have 5 different .sh scripts and run them all with a 6th one. How do I do that? example please. Thank you!

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Web Master
  • 4,240
  • 6
  • 20
  • 28
  • Related? [Running a Jar twice](http://stackoverflow.com/q/10256395/1983854) – fedorqui Jun 13 '16 at 10:33
  • Use something like `java -jar lol.jar & java -jar lol.jar & ...`. See [Execute several programs at the same time in an initialisation/bash script](http://stackoverflow.com/questions/430176/execute-several-programs-at-the-same-time-in-an-initialisation-bash-script) – Jesper Jun 13 '16 at 10:35

2 Answers2

4

You can try to run your java processes as deamons

You can daemonize any executable in Unix by using nohup and the & operator:

#!/bin/bash
nohup java -jar lol.jar &
nohup java -jar lol.jar &
nohup java -jar lol.jar &
nohup java -jar lol.jar &
nohup java -jar lol.jar &
Lorenz Pfisterer
  • 802
  • 7
  • 17
3

Multiple ways:

  1. Why don't you write java threaded program.

  2. Append '&' at each line as follows. It runs your command in background. java -jar lol.jar &

    Next you can use following to make comma separated list of Process Ids for further control over running jars.
    PIDs=${PIDs},$!

  3. Use '&' and loop for i in {0..5}; do java -jar lol.jar & ; done
Rohit Verma
  • 457
  • 2
  • 13