I need a shell script to simultaneously run multiple instances of a compiled c code
can some one please help i'm using BASH

One way to do it, also assuming know how many instances of it you want to run, is in a loop, start the process in the background.

while (x < counter){
  ./process&
  x++;
}

One way to do it, also assuming know how many instances of it you want to run, is in a loop, start the process in the background.

while (x < counter){
  ./process&
  x++;
}

thanks for that
but the code is giving an error

./runall.sh: line 7: syntax error: unexpected end of file

the actual code being in file runall.sh the counter is 100(ie. 100 instances of the compiled code

#!/bin/bash
while (x < 101)
        {
          ./<filename> &
           x++;
        }

i am a beginner to shell scripting so please bear with me

The while loop was pseudocode to give you an idea of what you might need. I am sorry if I confused you.

Check out this tutorial, that tells you how to do loops in bash scripting.

Change this

#!/bin/bash
while (x < 101)
        {
          ./<filename> &
           x++;
}

To this and you should be good

#!/bin/bash

x=1
while [ $x -lt 101]
do
          ./filename &
           let x=$x+1
done

The bash tutorial referenced in a previous post is a good read if you're going to be doing this a lot. There are more succinct ways of getting this done using bash's built-ins, but, I'm an old dog ;)

Best wishes,

, Mike

This article has been dead for over six months. Start a new discussion instead.