[bash] Run a program many times

Login or Register to Reply

Thread Tools Search this Thread
# 1  
[bash] Run a program many times


I'm running a program many times with differents input.
I mean that i run my_prog with some parameters and i wait till the end, then i start again another simulations with some others differents parameters.

Is possible to make it automatic with a script bash.
Maybe i need some function to check if the program has completed its task.



Sorry for the post. I've already found a solution.
We can use the pidof function. It works like:

if [ (pidof process_name) ] then

echo "It's already running"


echo "Not running"

Last edited by Dedalus; 08-17-2009 at 11:12 AM.. Reason: solution found
# 2  
is like you say xD
if pidof $1 
    echo "Is runnig"
    echo "Is NOT runnig"

# 3  
Re; [bash] Run a program many times

Any reason why you wouldn't use "wait" ?

I'm assuming from what you say the program is running in the background, hence the issue with regards to knowing what it's finished .. how about something like;

for i in `cat parameters`
    echo "Testing with $i"
    time ./my_prog $i
    wait $!

Depending on your parameters you'll probably need something a little more complete than "cat parameters", but in principle this will wait for my_prog to finish even if it backgrounds ..

Or .. for a batch in parallel ..

function me()
    ./my_prog $1
    list="$list $!"

for i in `cat parameters`
    echo "Testing with $i"
    time me $i

wait $list

'Course if they all finish around the same time, the output from "time" might be interesting to interpret ... Smilie
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Run a job between times else run later
Hi guys, I have written a script that waits for a trigger file. Then checks the time of the trigger. if the trigger finished between 8pm and midnight then runs a job. else it waits till 1am then runs a different job. I am still very new to scripting so any suggestions to improve my...... Shell Programming and Scripting
Shell Programming and Scripting
shell program- how many times a function is called
We have a program source C and is required to indicate how many times each function is called from the C program. also print the line number where there is a call. I've tried something like this: #!/bin/sh for i in $*;do if ! then echo $i is not a C file. else echo $i...... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
Compare times to run a program - Serial vs MPI
Hi, I have a fortran program with serial and MPI version. I want to compare the time taken by these programs to run. I use ifort/gfortran compiler. How to compare the time taken by each program to run? Is there any sample code for comparison? Thanks, rpd... Programming
Run Program from Bash CGI-Script
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This is a problem I am having with my 2 semester senior project. I have a LAMP server running Ubuntu 9.10 with...... Homework & Coursework Questions
Homework & Coursework Questions
Can I use $1 several times in shell program?
Hi, I am new to Unix and shell programming. I am trying to write a shell program to read 4 variables from command line. For example, Please enter your name: somebody Please enter your address: address plase enter your phone: phone I'd like to save all threee variables in my program for...... Shell Programming and Scripting
Shell Programming and Scripting