I am writing a script, but there is something I need that I can't find a way to do it...
I need to make a command in background "command1 &" and then somewhere in the script I need to wait for it to finish before I do command2. Basically, I need this:
NOTE: each command runs in a specific directory! at the end of the while loop my command1 created 4 directory's, where in each one run the specific process so the total of process running are 4
a=1
while [$a -lt 4 ]
. command1
#Generates 1 Process
a= `export $a +1`
done
#Wait until the 4 process end and then run the command2
. command2
I've seen something about a wait
command with the pid process number, but that didn't work also.
command1
? Can you modify it so that it returns the PIDs of the 4 processes? – terdon Apr 10 '14 at 15:18$!
variable to get this, passing it to thewait
command as I showed there.$!
contains the last backgrounded PID, while$$
contains the last process run's PID. – slm Apr 10 '14 at 15:40