Find the answer to your Linux question:
Results 1 to 3 of 3
I am trying to write a bit of a script to send a command to run a script several times, which in turn runs another script which runs a program. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2006
    Location
    York
    Posts
    9

    Unhappy wait command problems


    I am trying to write a bit of a script to send a command to run a script several times, which in turn runs another script which runs a program. This is what i have:

    Code:
    for i in $(seq 1 10) #runs rdocking 10 times
    do
        rdocking $MYTEST &
        rpid=$!
        wait $rpid
        echo "$i docking test(s) complete!"
    done
    Wait does work for this, but it only waits until the first one is done and not the two within it.
    I have tried using the batch command but it causes a problem due to the fact that i am unable to see the processes or jobs that it is carrying out, and therefore i am unable to control them.

    the wait man page says:
    wait [n]
    Wait for the specified process and return its termination sta-
    tus. n may be a process ID or a job specification; if a job
    spec is given, all processes in that job’s pipeline are waited
    for.
    Is there something like a job pipeline i need to set up? Does anyone have any ideas?

    EDIT: Problem sorted, it was something else messing the progam up (though i am not sure what!)

  2. #2
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Location
    Maryland, USA
    Posts
    510
    I have an idea in mind, but the implementation would be messy, so I'll just describe it.

    Create a directory, like ~/pids.
    Each script puts it's own PID into the directory before anything else and deletes it when done.
    Code:
    touch ~/pids/$$
    Each script is passed a list of the PIDs of it's ancestors, and it adds it's own and passes it to it's children:
    Code:
    PIDLIST="$PIDLIST $$"
    rdocking $MYTEST "$PIDLIST"
    Now, the messy part: Each script has to wait for every PID in ~/pids that is NOT in the PIDLIST it received (and of course, is not itself).

  3. #3
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Quote Originally Posted by KenJackson
    I am trying to write a bit of a script to send a command to run a script several times, which in turn runs another script which runs a program.
    And why don't you launch the program in the background? It would be easier if you simple lauch:

    rdocking $MYTEST

    This will lock your top level script until the command has finished, won't it?

    Best regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •