Multiple *Almost* identical processes on a Linux Server

Solution 1:

I'd argue that if a process fails, you need to fix it in order to not fail anymore.

To do what you expect, something like this would suffice (untested, use at your own risk):

#!/bin/bash
for i in $(seq 1 4)
do
  (
    echo "Starting node $i..."
    while ! java -DNodeNumber=$i CalculationNode
    do
      sleep 1
      echo "Restarting node $i..."
    done
  ) &
done
wait

Each process has to finish with exit code zero in order to break the loop. Otherwise, it is restarted by the script.