multiple runs of a program

This is a discussion on multiple runs of a program within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I've just built a program that I'm wanting to run many times with different variables. e.g myprog -h 2 ...

  1. #1
    unregistered
    Guest

    Question multiple runs of a program

    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

  2. #2
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    Making a script comes to mind. You could enter the following in a text file:
    Code:
    #!/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.
    Jason Deckard

  3. #3
    Unregistered
    Guest
    thanks thats just what I was after,
    john

  4. #4
    Registered User rohit's Avatar
    Join Date
    Feb 2002
    Posts
    69
    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

  5. #5
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    Originally posted by rohit
    so you could have done like this too
    Or 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:
    Code:
    #!/bin/bash
    myprog -h 2 -b 4 &
    myprog -h 3 -b 4 &
    myprog -h 4 -b 4 &
    myprog -h 5 -b 4 &
    Jason Deckard

  6. #6
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    with newer versions of bash (I use 2.05), you can use this:
    Code:
    #!/usr/local/bin/bash
    for (( i=0 ; i<=1000 ; i++ )); do
       myprog -h $i -b 4;
    done;
    alex

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  3. Error when my program runs
    By Just4Learning in forum C++ Programming
    Replies: 3
    Last Post: 05-22-2007, 08:20 PM
  4. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  5. Replies: 18
    Last Post: 12-05-2003, 12:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21