multiple runs of a program [Archive] - C Board

PDA

View Full Version : multiple runs of a program


unregistered
03-13-2002, 10:56 AM
Hi,

I've just built a program that I'm wanting to run many times with different variables. e.g

myprog -h 2 -b 4
myprog -h 3 -b 4
myprog -h 4 -b 4
myprog -h 5 -b 4

...

myprog -h 1000 -b 4

I heard there was away to do this in unix, could someone point me in the right direction please as I'm very new to this whole unix thing,

Thanks

John

Deckard
03-13-2002, 11:41 AM
Making a script comes to mind. You could enter the following in a text file:

#!/bin/bash
myprog -h 2 -b 4
myprog -h 3 -b 4
myprog -h 4 -b 4
myprog -h 5 -b 4
Then make the file executable with chmod 755 <filename>. Now just execute the script and you're in business.

A word of warning: using 755 as your chmod value allows any user to execute your script. Using the value 700 takes care of that by only allowing you (and root) read, write, and execute permissions.

Unregistered
03-13-2002, 06:45 PM
thanks thats just what I was after,
john

rohit
03-13-2002, 10:49 PM
by this there will always be only one instance running cause your program is a blocking i suppose and shells do not execute the other command lines unless they are done with the present commands on the lines

so you could have done like this too

SHELL# > program arguments ; program other arguments ; program more other arguments;

one i suppose to call a program from itself you will have to do something like this

exec(call your program again from here) but again this will lead to no where

or use fork or use pthreads


and

is your program thread safe


cheers
Rohit

Deckard
03-14-2002, 11:38 AM
Originally posted by rohit
so you could have done like this tooOr you can stick an ampersand (&) after each command, forcing them to run in the background. The shell will then execute the next command before the previous one completes:
#!/bin/bash
myprog -h 2 -b 4 &
myprog -h 3 -b 4 &
myprog -h 4 -b 4 &
myprog -h 5 -b 4 &

alex
03-15-2002, 07:18 AM
with newer versions of bash (I use 2.05), you can use this:

#!/usr/local/bin/bash
for (( i=0 ; i<=1000 ; i++ )); do
myprog -h $i -b 4;
done;

alex