forking in multithreaded program


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users forking in multithreaded program
# 1  
Old 04-22-2009
forking in multithreaded program

hi all,

i am using pthreads.

What will happen if a thread does a fork?
will all the threads are duplicated for the new process or only the called thread is duplicated?
are the resources shared across the processes?

thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

need help in forking

I have an input file with contents like: 5785690|68690|898809 7960789|89709|789789 7669900|87865|659708 7869098|65769|347658 so on.. I need to pass this file to 10 parallely running processes (forking)so that each line is processed by a process and no line is processed twice and write the... (1 Reply)
Discussion started by: rkrish
1 Replies

2. Programming

Basic multithreaded program

I'd like to write a program (I'm flexible on language; C/C++ was my original idea but a scripting language would probably be better) that runs hundreds of programs, but only N = 4 (say) at a time. The idea is to keep all the cores on a multicore machine busy. How can I do this? In particular,... (6 Replies)
Discussion started by: CRGreathouse
6 Replies

3. Shell Programming and Scripting

Problem with forking

Hi, my $log = IO::File->new(">$log_file_name"); $log->print("date()."--\n\n\n"); sub process { my ($sub_dir, $file, $config, $log) = @_; $log->print("-- Reading $file file\n"); } my $pm = new Parallel::ForkManager($tc+1); $pm->run_on_finish( sub { my ($pid, $exit_code,... (1 Reply)
Discussion started by: sandy1028
1 Replies

4. Shell Programming and Scripting

execute command multithreaded util without programming

Hello all is there any way in unix to execute command in multithreaded way without doing it in java or cpp can one of the scripts handle multithread execution ? i need to test server requests ( corba ) in multithread Thanks (0 Replies)
Discussion started by: umen
0 Replies

5. Shell Programming and Scripting

Forking with Tclsh vs Wish

Hello, I am new to this site, so sorry ahead of time if this is not the right place for this question.......anywhooooo I am having troubles with forking new processes in wish. Take the following code example: **************************** package require Tclx puts "TCL VER: " proc... (3 Replies)
Discussion started by: pghamami
3 Replies

6. Programming

getting problem in my code:::: plz help...(multithreaded appn with serial comm.)

hello, here I am copying my code... I am using two threads for reading and writing at com ports....one for reading and one for writing...in read thread I am using select() api....and polling again and again if there is some data to be read....but select is not returning any positive value so... (0 Replies)
Discussion started by: arunchaudhary19
0 Replies

7. Linux

getting problem in my code:::: plz help...(multithreaded appn with serial comm.)

hello, here I am copying my code... I am using two threads for reading and writing at com ports....one for reading and one for writing...in read thread I am using select() api....and polling again and again if there is some data to be read....but select is not returning any positive value so... (0 Replies)
Discussion started by: arunchaudhary19
0 Replies

8. Programming

forking within a thread

Is it safe to call fork+exec in a multithreaded application. Because In my multithreaded application, I need to execute another program in each thread. I am using solaris 10. Any suggestions pls. (2 Replies)
Discussion started by: axes
2 Replies

9. UNIX for Advanced & Expert Users

Forking

When I compile this C programme I get different outputs each time I run it Please explain to me whats happening in the code if you can give me a detailed explanation with the schedular functionality it will help a lot. Because I am stuck with this. #include <stdio.h> main(){... (3 Replies)
Discussion started by: manjuWicky
3 Replies

10. Programming

Getting errno in a Multithreaded program

In Tru64 Unix, the 'errno' variable is not thread safe. Could anybody help me about how to make it thread safe or how to check 'errno' in a Multithreaded program ???? The Programming process is like this. There are some definite number of threads having their own task. There is one... (2 Replies)
Discussion started by: S.Vishwanath
2 Replies
Login or Register to Ask a Question
PTHREAD_DETACH(3)					     Linux Programmer's Manual						 PTHREAD_DETACH(3)

NAME
pthread_detach - detach a thread SYNOPSIS
#include <pthread.h> int pthread_detach(pthread_t thread); Compile and link with -pthread. DESCRIPTION
The pthread_detach() function marks the thread identified by thread as detached. When a detached thread terminates, its resources are automatically released back to the system without the need for another thread to join with the terminated thread. Attempting to detach an already detached thread results in unspecified behavior. RETURN VALUE
On success, pthread_detach() returns 0; on error, it returns an error number. ERRORS
EINVAL thread is not a joinable thread. ESRCH No thread with the ID thread could be found. CONFORMING TO
POSIX.1-2001. NOTES
Once a thread has been detached, it can't be joined with pthread_join(3) or be made joinable again. A new thread can be created in a detached state using pthread_attr_setdetachstate(3) to set the detached attribute of the attr argument of pthread_create(3). The detached attribute merely determines the behavior of the system when the thread terminates; it does not prevent the thread from being terminated if the process terminates using exit(3) (or equivalently, if the main thread returns). Either pthread_join(3) or pthread_detach() should be called for each thread that an application creates, so that system resources for the thread can be released. (But note that the resources of all threads are freed when the process terminates.) EXAMPLE
The following statement detaches the calling thread: pthread_detach(pthread_self()); SEE ALSO
pthread_attr_setdetachstate(3), pthread_cancel(3), pthread_create(3), pthread_exit(3), pthread_join(3), pthreads(7) COLOPHON
This page is part of release 3.27 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 2008-11-27 PTHREAD_DETACH(3)