race condition with wait() function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting race condition with wait() function
# 1  
Old 12-02-2008
race condition with wait() function

Hi,
I'm currently writing a bash script, that starts multiple threads:
____________________
#!/bin/bash
loop=0
while((loop!=10))
do
thread &
((loop++))
done

#wait for all sub-processes (thread) to finish
wait
___________________

Now I want to know, what happens, if a sub-process (thread) is finished,
before the main-script gets to the wait parameter.
Will the wait parameter realize, that the thread has already finished or will it wait to infinity?

Thnaks for your help...
# 2  
Old 12-02-2008
Wait will only wait on active child processes. Dead processes (or terminated, or non-existant) will not be waited for.
# 3  
Old 12-02-2008
thank you for your fast answer.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

wait() function...

when wait() is called by process it blocks calling process until child is done. What happens if calling process have multiple children. What does wait(NULL) function do. Waits until all children are done? (1 Reply)
Discussion started by: joker40
1 Replies

2. Shell Programming and Scripting

Wait function in a script

Hi everyone, I need some help to create a script. This script have to create a file once all the process inside are finish. Here how I want to do : #!/bin/ksh /home/oracle/save1.ksh & proc_id1=$! /home/oracle/save2.ksh & proc_id2=$! /home/oracle/save3.ksh & proc_id3=$! ... (4 Replies)
Discussion started by: remfleyf
4 Replies

3. Programming

problem about race condition

Hi all, i'm reading Andrew S.Tanenbaum's book --- Modern Operating System.At the part of discussing race condition.And the author gives a solution with using the TSL instruction,say that one process must call the enter_region function before entering the critical regions and call the leave_region... (0 Replies)
Discussion started by: homeboy
0 Replies

4. Programming

Race condition with PTY

I've been experimenting with pseudo-terminals and found something I don't quite understand. Writing an EOF character to the master end doesn't work quite as I expect. Once I've written any other data, the master pty seems to treat a single ^D as a seperator, i.e. writing "abcabc" would let cat do... (1 Reply)
Discussion started by: Corona688
1 Replies

5. Programming

In unix how we can test or check race condition in a c program by using multi threads

In unix how we can test or check race condition in any c program by using multi thread programming (1 Reply)
Discussion started by: afroze
1 Replies

6. Programming

In unix how we can test or check race condition in c program by using multi threads

In unix how we can test or check race condition in any c program by using multi thread programming (5 Replies)
Discussion started by: afroze
5 Replies

7. UNIX for Dummies Questions & Answers

In unix how we can test or check race condition in a c program by using multi threads

In unix how we can test or check race condition in any c program by using multi thread programming (1 Reply)
Discussion started by: afroze
1 Replies

8. Linux

In unix how we can test or check race condition in c program by using multi threads

In unix how we can test or check race condition in any c program by using multi thread programming (1 Reply)
Discussion started by: afroze
1 Replies
Login or Register to Ask a Question