How to make parent shell finish last?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make parent shell finish last?
# 1  
Old 12-08-2009
How to make parent shell finish last?

Hi all,
I have a shell that kicks off several sub-shells and make them run parallelly, like:

shell1.sh &
shell2.sh &
shell2.sh &
...

However, since all sub-shells run parallely, the parent shell finished right after it's submitted, like:
$ parent.sh &
$ [2] + Done parant.sh &
$

Though sub-shells are still runing.
Is it possible to make the parent.sh finishes only after all its sub-shells finished and still let the sub-shell runs parallely?
# 2  
Old 12-08-2009
For example:

Code:
$ cat parent.sh
./shell1.sh &
./shell2.sh &
./shell3.sh &

wait %1
echo 1 finished
wait %2
echo 2 finished
wait %3
echo 3 finished
# end of parent.sh



$ ./parent.sh &
[1]     4759572

$ jobs
[1] +  Running                 ./parent.sh &

1 finished Tue Dec 8 15:44:05 NFT 2009
2 finished Tue Dec 8 15:44:11 NFT 2009
3 finished Tue Dec 8 15:44:17 NFT 2009


[1] +  Done                    ./parent.sh &


Last edited by Scott; 12-09-2009 at 05:01 PM.. Reason: Clarify what is "parent.sh"
# 3  
Old 12-08-2009
Thanks. I will try.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How make parent to wait from child process?

Hi all, I am starting mgen5 for sometime depends on input from a file, in a child process. now I want to make parent to wait in this child process till mgen5 finishes, or timeout happens. could anyone please tell me how to make parent to wait in child process in shell script? thanks... (2 Replies)
Discussion started by: girijajoshi
2 Replies

2. Programming

Pass parameter from a child make to a parent

Hello, I have the following problem: I have makefileproj and makefilemod in a build process for a complex project - from makefileproj I call the makefilemod. In makefilemod I generate a list containing objects eg,: "../../../25_Build/Results/Objects/FBL/Fls.o... (4 Replies)
Discussion started by: marina_lmv
4 Replies

3. Shell Programming and Scripting

Kill a process from parent shell within a shell script

Hi, I am looking for a solution for the following problem: Im Using tcpdump within a shellskript started in a subshell by using brackets: ( /usr/sbin/tcpdump -i ... -c 1 ) - I want the outout of tcpdump saved in a variable - Than tcpdump-Process in the Subshell should be killed - and I... (6 Replies)
Discussion started by: 2retti
6 Replies

4. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

5. UNIX for Advanced & Expert Users

input to Parent shell

how can we give input to parent shell? i mean shell that is creating a child and our c prograame will run on that child..and then it return to parent shell.. what i want to do i want execute a c programe that will give command as input to parent shell & get output from parent shell and... (1 Reply)
Discussion started by: gajju
1 Replies

6. Programming

How can I make the parent thread wait

Hi All, I will be glad if you could help me resolve this problem. I have created two detachable threads and wanted to them execute independent of the parent thread ( the main task which creates the detachable threads). But I see no output coming from the execution of two detachable threads.... (4 Replies)
Discussion started by: jayfriend
4 Replies

7. UNIX for Advanced & Expert Users

how to make a parent wait on a child shells running in background?

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)
Discussion started by: albertashish
1 Replies

8. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies

9. Shell Programming and Scripting

parent shell is waiting upon the child shell

Hi, I haev to devlop a script which when executed will take in a sudo privelege and run a set of commands then will go back to parent shell and execute the rest of the command But the problem I am facing is that when the script is executed it takes the sudo privelege but it waits for the... (0 Replies)
Discussion started by: ruchirmayank
0 Replies

10. UNIX for Advanced & Expert Users

How can I wait for PID to finish in another shell

Have a need to schedule programs that can run after other programs are completed. Here's the catch: 1) The list of programs will not always be the same (kind of a plug-n-play deal) 2) The invoking shell may not be the same as the shell of the program being waited on In other words, I need... (2 Replies)
Discussion started by: superdelic
2 Replies
Login or Register to Ask a Question