How to make sure that sub shells have finished before moving on?
Hello,
I have a script that is running multiple instances of an application in parallel.
There are short sleep instances between where each instance is called. This helps keep the output to the terminal from getting garbled as multiple programs are printing at the same time. When all the instances have returned a separate program is called to process the output.
The problem I am having is that the output processing app (stats4A) is getting called before all of the instances have finished. I think that if f4 finishes before the others, then the script proceeds to call the stats program.
This more or less calls for a mutex to keep the stats program from running until everything has finished. There is no way to guarantee that f4 will finish after the others. You can see that I am already waiting 4 minutes as a measure to address this, but it appears that does not always work.
The only thing I can think of at the moment would be to have a 0/1 variable for each instance. That variable would initialize to 0. I would call the instances in a function, instead of inline, and have the function set the variable to 1 after the instance has returned. Then I would need the stats calls to be in something like a while loop that would not call stats until all of the values were 1. In other words, something needs to loop until all the values are 1 and then move on to the stats calls.
This would be relatively easy in cpp, but I really have no idea in bash. Is there a standard way to do this in a shell script? I can't imagine I am the first person to run across this.
Hi, the wait command should be sufficient. You could try that and run emergent -nogui -p $ScriptLoc/$PROJ fold_tag=f4 in the background as well and leave out the sleep 240... and likewise for the rest of the script with a second wait statement after the statistics scripts that run in the background..
So something like this:
Last edited by Scrutinizer; 08-20-2013 at 04:07 PM..
This User Gave Thanks to Scrutinizer For This Post:
Scrutinizer,
Thanks, that will simplify some other things as well. These sets do not always have the same number of instances and it is a pain to add logic to decide which instance doesn't get the & at the end of the call. That makes this hard to do in a loop.
DGPickett,
It sounds like you are going to read a file to figure out when a command has returned. I'm not sure how that would get integrated into this script. What would you be looking for in the log file to know that what ever you were running was finished? I though about checking for the existence of the last output file written by each instance, but those files exist along time before the app is done writing to them. For reference, the script I posted takes about 12 hours to finish.
No! All the children inside () for all generations inherit stdout and stderr from (), and when the last of them exists, the pipe into cat gets EOF and cat terminates. Nothing has to be written (but centralized logging is good). None of the commands inside () has to redirect stdout or stderr to get their errors logged, so the scripts are shorter, far less cluttered.
I am running a macro script from the command line. But the script doesn't wait until the task has finished.
firefox imacros://run/?m=macro_script.iim
firefox imacros://run/?m=macro_script2.iim
How do I get it to wait until the macro has been completed?
I am using imacros, a firefox... (1 Reply)
I have a script which uses cli curl to download the source code of a webpage and then tests if a specific string exists in the source.
The problem is that the website has a slow response, so the eval expression hasn't completed when the test starts.
The test returns a negative, and the curl... (8 Replies)
I'm working with recv and I am having a heck of a lot of trouble ignoring excess data that I did not ask for. I was hoping someone could shine some light on the subject for me because I'm not getting anywhere fast.
---------- Post updated at 02:46 AM ---------- Previous update was at 12:31 AM... (2 Replies)
Hi
I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running.
My Code:
... (1 Reply)
Hi all,
I am writing a C shell script that starts a program. The program forks of several child processes. Only when all child processes are done, I want to archive my log files. Below is what I have so far, but unfortunately it doesn't work.
MyProgram
if (-e processes.txt) then
rm... (2 Replies)
Hi frnds,
I want to know is there a way by which we can know that a C++ executable has finished its job in shell script.
My task is as follows:
1.Shell script calls a executable
2.Executable executes and performs its job of generating some reports.
Now i want my shell script to... (4 Replies)
Hello all
I have to run manually make commands in our system the make compilations task's takes very long
And I like to be able to run another make task right after one is finished.
What is the best way to automate it ? (2 Replies)
So, the script I've been working on, since I was starting to learn Shell scripting is now complete.
This was coded in ksh, and I am very proud of it.
What this script does, is syncs up uid's across the network. So if you have 10 servers, with 10 usernames with different UID's - this will... (1 Reply)
Hi
I'm writing a script which will be run by cron every X minutes.
I don't want cron to run my script again if the previous one has not yet finished.
When the script first runs, I had the idea to store the Process ID in a file. When cron tries to run the script again, I would check the... (5 Replies)
Problem
I have an application which basically runs lots of UNIX programs remotely, using the Telnet protocol. For each program it remotely executes, it stores the process ID (PID) for that process.
At regular intervals, I would like my application to take the PID for every process still... (5 Replies)