11-20-2008
main() isn't exactly a parent thread. exit() is called when it returns, that kills the process, and you can't have threads without a process. If you want things to be truly independent you need to create new processes.
If you just want main() to wait, don't make them detachable and use pthread_join() like everyone says, that's what it's for.
Last edited by Corona688; 11-20-2008 at 09:25 PM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
is there a way to make my script wait before doing something without using the "sleep _" command? (4 Replies)
Discussion started by: Blip
4 Replies
2. UNIX for Advanced & Expert Users
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
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
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 &
$ + Done parant.sh &
$
... (2 Replies)
Discussion started by: visio2000
2 Replies
5. Shell Programming and Scripting
I am trying to find a list of files and writing it to a text file. Based on the machine performance the file writing will be slow at certain time.
The code to find file and redirecting the output to text file is on a shell script
/usr/bin/find $SEARCH_DIR -daystart \( \( -name 'KI*' -a... (4 Replies)
Discussion started by: nuthalapati
4 Replies
6. Programming
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
7. Programming
Parent Thread Of Child Thread
Suppose a process creates some threads say threadC and threadD.
Later on each of these threads create new child threads say threadC1, threadC2, threadC3 etc. So a tree of threads will get created.
Is there any way to find out the parent thread of one such... (1 Reply)
Discussion started by: rupeshkp728
1 Replies
8. Programming
Hello. I want to make a child do some stuff,wait,then the parent does some stuff and then child does some stuff and waits again.I have made the following but it does not work.Can anybody help me?
pid1 = fork();
if (pid1 == -1)
{
perror("Can't create child\n");
... (18 Replies)
Discussion started by: Cuervo
18 Replies
9. Shell Programming and Scripting
I have two scripts lets say A.expect and B.sh needs to be executed.
I am executing B.sh from A.expect where B.sh has sleep command.
My problem is that when B.sh encounters the sleep command my A.expect starts executing and exits.
but my A.expect should execute only after completing B.sh.
Is... (3 Replies)
Discussion started by: priya@2012
3 Replies
10. Shell Programming and Scripting
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
LEARN ABOUT REDHAT
thr_join
thr_join(3C) Standard C Library Functions thr_join(3C)
NAME
thr_join - wait for thread termination
SYNOPSIS
cc -mt [ flag... ] file...[ library... ]
#include <thread.h>
int thr_join(thread_t thread, thread_t *departed, void **status);
DESCRIPTION
The thr_join() function suspends processing of the calling thread until the target thread completes. The thread argument must be a member
of the current process and cannot be a detached thread. See thr_create(3C).
If two or more threads wait for the same thread to complete, all will suspend processing until the thread has terminated, and then one
thread will return successfully and the others will return with an error of ESRCH. The thr_join() function will not block processing of the
calling thread if the target thread has already terminated.
If a thr_join() call returns successfully with a non-null status argument, the value passed to thr_exit(3C) by the terminating thread will
be placed in the location referenced by status.
If the target thread ID is 0, thr_join() finds and returns the status of a terminated undetached thread in the process. If no such thread
exists, it suspends processing of the calling thread until a thread for which no other thread is waiting enters that state, at which time
it returns successfully, or until all other threads in the process are either daemon threads or threads waiting in thr_join(), in which
case it returns EDEADLK. See NOTES.
If departed is not NULL, it points to a location that is set to the ID of the terminated thread if thr_join() returns successfully.
RETURN VALUES
If successful, thr_join() returns 0. Otherwise, an error number is returned to indicate the error.
ERRORS
EDEADLK A joining deadlock would occur, such as when a thread attempts to wait for itself, or the calling thread is waiting for any
thread to exit and only daemon threads or waiting threads exist in the process.
ESRCH No undetached thread could be found corresponding to the given thread ID.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO
thr_create(3C), thr_exit(3C), wait(3C), attributes(5), standards(5)
NOTES
Using thr_join(3C) in the following syntax,
while (thr_join(0, NULL, NULL) == 0);
will wait for the termination of all non-daemon threads, excluding threads that are themselves waiting in thr_join().
SunOS 5.10 27 Mar 2000 thr_join(3C)