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 DEBIAN
pthread_exit
PTHREAD_EXIT(3) Linux Programmer's Manual PTHREAD_EXIT(3)
NAME
pthread_exit - terminate calling thread
SYNOPSIS
#include <pthread.h>
void pthread_exit(void *retval);
Compile and link with -pthread.
DESCRIPTION
The pthread_exit() function terminates the calling thread and returns a value via retval that (if the thread is joinable) is available to
another thread in the same process that calls pthread_join(3).
Any clean-up handlers established by pthread_cleanup_push(3) that have not yet been popped, are popped (in the reverse of the order in
which they were pushed) and executed. If the thread has any thread-specific data, then, after the clean-up handlers have been executed,
the corresponding destructor functions are called, in an unspecified order.
When a thread terminates, process-shared resources (e.g., mutexes, condition variables, semaphores, and file descriptors) are not released,
and functions registered using atexit(3) are not called.
After the last thread in a process terminates, the process terminates as by calling exit(3) with an exit status of zero; thus, process-
shared resources are released and functions registered using atexit(3) are called.
RETURN VALUE
This function does not return to the caller.
ERRORS
This function always succeeds.
CONFORMING TO
POSIX.1-2001.
NOTES
Performing a return from the start function of any thread other than the main thread results in an implicit call to pthread_exit(), using
the function's return value as the thread's exit status.
To allow other threads to continue execution, the main thread should terminate by calling pthread_exit() rather than exit(3).
The value pointed to by retval should not be located on the calling thread's stack, since the contents of that stack are undefined after
the thread terminates.
BUGS
Currently, there are limitations in the kernel implementation logic for wait(2)ing on a stopped thread group with a dead thread group
leader. This can manifest in problems such as a locked terminal if a stop signal is sent to a foreground process whose thread group leader
has already called pthread_exit().
SEE ALSO
pthread_create(3), pthread_join(3), pthreads(7)
COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2009-03-30 PTHREAD_EXIT(3)