Use fork() in thread


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Use fork() in thread
# 1  
Old 10-31-2008
Question Use fork() in thread

Hi experts,
I have a plan to implement following schema:
multi-threaded pthreads application with exactly 3 threads.
One thread calls from time to time fork(), and from the child process it executes an unix command by execv().

Is that safe design? I've heard rumors that mixing threads and processes is a bad idea, but did not find any specific info.

I plan to implement the schema in Linux and Solaris.

Thanks in advance!
# 2  
Old 11-02-2008
Are you planning to use pthread_atfork()?
# 3  
Old 11-10-2008
fpmurphy, thanks for the hint!,
I found this post:
comp.unix.programmer: Re: fork() from a thread (pthreads)
That explained all my concerns.

Also Programming with POSIX® Threads by David R. Butenhof explains much of what I needed.


Thanks,
Pavel.
# 4  
Old 11-11-2008
Quote:
Also Programming with POSIX® Threads by David R. Butenhof explains much of what I needed.
An excellent book. Dave was deeply involved with the development of POSIX.1c.

I note that you mention that you will be developing for both Solaris and Linux. Linux has a number of threading models as does Solaris and the threads implementations vary depending on the particular OS version your application is running on. Test and test again!
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Not able to post thread/reply to thread

Dear Moderator I am not able to post any new thread or post reply to mine old thread. Kindly help as i am stuck on one problem and needed suggestion. Regards Jaydeep (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies

2. Programming

Fork thread, Assertion failed. X11.

Hi all. I wrote a program with the Motif Widget Toolkit. It has a button and a scrollbar. When the user hits the button the callback creates a new fork() thread. The new thread sleeps for a while and then changes the position of the scrollbar. It does this in an endless loop. I need the... (2 Replies)
Discussion started by: mghis
2 Replies

3. Programming

Parent Thread Of Child Thread

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

4. Programming

How to cancel a thread safely from the initial thread?

how about asynchronous canceling? or with signal? if with signal whether it effects the process? my english so badly :( :( (1 Reply)
Discussion started by: alan.zhao
1 Replies
Login or Register to Ask a Question