pringlesCan
Junior Member
I would like to know how to do the following.
I have created a shell script that runs a series of simulations. These simulations take hours, so naturally I want to run them in the background and "nohup" them.
Moreover, I would like to do the following: run 5 simulations in this manner, and when those 5 simulations are complete, run the next 5 simulations.
I understand I can use the "wait" command to pause a script until a certain process completes. However, I have a problem trying to use the "wait" command in a script which is "nohup".
If I "'nohup" a script, do I have to "nohup" all commands it invokes? Otherwise the whole script is killed when I kill the session? Does anyone know how to accomplish something like this?
Very simple example
for i in 1 2 3 4 5
do
simCmd -args1 &
pid1=$!
simCmd -args2 &
pid2=$!
simCmd -args3 &
pid3=$!
simCmd -args4 &
pid4=$!
simCmd -args5 &
pid5=$!
wait $pid1
wait $pid2
wait $pid3
wait $pid4
wait $pid5
echo "5 Simulations have completed"
mv simResults* simResultsDir/.
done
Any help is appreciated. Thanks!
I have created a shell script that runs a series of simulations. These simulations take hours, so naturally I want to run them in the background and "nohup" them.
Moreover, I would like to do the following: run 5 simulations in this manner, and when those 5 simulations are complete, run the next 5 simulations.
I understand I can use the "wait" command to pause a script until a certain process completes. However, I have a problem trying to use the "wait" command in a script which is "nohup".
If I "'nohup" a script, do I have to "nohup" all commands it invokes? Otherwise the whole script is killed when I kill the session? Does anyone know how to accomplish something like this?
Very simple example
for i in 1 2 3 4 5
do
simCmd -args1 &
pid1=$!
simCmd -args2 &
pid2=$!
simCmd -args3 &
pid3=$!
simCmd -args4 &
pid4=$!
simCmd -args5 &
pid5=$!
wait $pid1
wait $pid2
wait $pid3
wait $pid4
wait $pid5
echo "5 Simulations have completed"
mv simResults* simResultsDir/.
done
Any help is appreciated. Thanks!