1

I have a server executable myserver. I have to start 5 instances of it with different IP addresses (provided through commandline). This is what I have tried:

for i in `seq 1 5`
do
    ip="127.0.0.$i"
    myserver $ip
done

The problem is that after starting first myserver, the control does not come to the terminal. How can I start the processes in background?

Appending with & i.e. myserver $ip & did not help. Most likely, I am doing something wrong with the last & that is used to run processes in background.

Edit: myserver has to continuously listen to a socket bound to its IP and a default port. Therefore, it has an infinite loop inside it.

1 Answer 1

3
for i in {1..5}
do
    ip="127.0.0.$i"
    myserver "$ip" &
done

wait # for all backgrounded jobs to finish
Sign up to request clarification or add additional context in comments.

1 Comment

The wait at the end is classy. :) but may be optional

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.