- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- fork usage in a multithreading environment
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2010 05:36 AM
тАО03-17-2010 05:36 AM
I have a multi-thread process, that in a specific thread executes a fork.
My question is: does the child process inerit all father process threads?
Thanks in advance
Giuseppe
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2010 05:44 AM
тАО03-17-2010 05:44 AM
Solution(emphasis mine)
-----
DESCRIPTION
The fork() system call causes the creation of a new process. The new child process is created with _exactly one thread_ or lightweight process. The new child process contains a replica of the calling thread (if the calling process is multi-threaded) and its entire address space, possibly including the state of mutexes and other resources.
[...]
-----
i.e. the answer is "No, only the thread calling fork() is replicated."
The same is true of the vfork() system call.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2010 06:14 AM
тАО03-17-2010 06:14 AM
Re: fork usage in a multithreading environment
From a perf point of view it should be avoided as long as possible.
To fork() the kernel need to stop all the parent threads before duplicating its memory and fds. They are resumed after those operations.
So avoid fork() in multithread applications
use coprocess to launch forked processes and communiate with that coprocess through pipe, UNIX socket, or any other mean to ask a launch. From a perf point of view it will be much better.
if you need to share fds, you can send fds through UNIX sockets. for instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2010 07:47 AM
тАО03-17-2010 07:47 AM
Re: fork usage in a multithreading environment
Note: system(3) also does a fork.
As Matti said, you only have the one thread. But libpthread would have to execute every atfork handler when you fork.
>Laurent: if you need to share fds, you can send fds through UNIX sockets
How can you do that unless you have a common grandparent?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2010 11:13 AM
тАО03-17-2010 11:13 AM
Re: fork usage in a multithreading environment
>How can you do that unless you have a common grandparent?
2 main ways:
one using /dev/echo and I_SENDFD/I_RECVFD ioctls
UNIX domain socket access right send with sendmsg() (man sendmsg)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 09:38 AM
тАО03-18-2010 09:38 AM
Re: fork usage in a multithreading environment
Thanks! Also, if you'd rather, I could create a new topic so I can assign some points too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 08:44 PM
тАО03-18-2010 08:44 PM
Re: fork usage in a multithreading environment
This is a developer question.
>I'm guessing you're writing a script or C program, but this is not clear.
This is very clear. It is a probably C or C++ program.
>I could create a new topic so I can assign some points too.
You should create your own thread for your different question.