The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Forking in Unix using C++ kkk02 High Level Programming 3 5 Days Ago 06:53 AM
forking process. kymthasneem High Level Programming 2 06-23-2007 10:00 AM
Forking manjuWicky UNIX for Advanced & Expert Users 3 10-07-2005 12:01 PM
Forking in a loop manjuWicky High Level Programming 1 10-07-2005 09:25 AM
How to cancel a thread safely from the initial thread? alan.zhao High Level Programming 1 04-29-2005 07:07 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-01-2007
Registered User
 

Join Date: Mar 2006
Posts: 45
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.
Reply With Quote
Forum Sponsor
  #2  
Old 07-01-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,658
Yeah, it's safe in a general sense. I believe that Solaris 10 has fork1() available (and if it does, forkall() would be there too). fork1() is supposed to replicate only the current thread in the new process and there may be a performance boost available by that. But I have not used fork1()/forkall() so I'm not sure. Anyway, I would give fork1() a try.
Reply With Quote
  #3  
Old 07-01-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by axes View Post
I need to execute another program in each thread.
Each thread may call fork() then exec() if that is what you mean?

The rules are that are that after fork() only one thread is running in the child process, and that was the thread that called fork().

Also have a look at pthread_atfork() and see if you need to do anything to protect mutexes etc.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0