[nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation
- From: "Karan, Cem F CIV USARMY RDECOM ARL (US)" <cem.f.karan.civ@xxxxxxxx>
- To: "nanomsg@xxxxxxxxxxxxx" <nanomsg@xxxxxxxxxxxxx>
- Date: Thu, 15 Dec 2016 13:58:55 +0000
-----Original Message-----
From: nanomsg-bounce@xxxxxxxxxxxxx [mailto:nanomsg-bounce@xxxxxxxxxxxxx] On ;
Behalf Of Franklin Mathieu
Sent: Thursday, December 15, 2016 4:10 AM
To: nanomsg@xxxxxxxxxxxxx
Subject: [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and
fork()-safe implementation
2016-12-15 2:28 GMT+01:00 Garrett D'Amore <garrett@xxxxxxxxxx>:
Please refer to the Open Group specifications for this. fork
duplicates the process memory image, but does not duplicate the
threads themselves. I take that to mean the memory other than for the
pthread itself will be “duplicated”, and that if the only reference to
said memory (directly or
indirectly) was on a stack frame for a thread that got left behind,
then the memory will be orphaned.
On Wed, Dec 14, 2016 at 1:57 PM, Karan, Cem F CIV USARMY RDECOM ARL
(US) <cem.f.karan.civ@xxxxxxxx> wrote:
Makes sense. I can see how the standard library calls are difficult
to deal with; you have no control over how that memory is allocated.
I'm going to expose my ignorance here; does fork() duplicate
structures allocated by pthreads? I know it duplicates file
descriptors, but I don't know what else it duplicates. Off hand, do
you know of a complete list of what fork() duplicates?
There are also corner cases w.r.t. file descriptors inheritance depending on
the platform.
A notable example I had with the current nanomsg codebase are kqueue file
descriptors, which are not inherited though fork().
These corner cases are what I was concerned about. I just read the spec at
http://pubs.opengroup.org/onlinepubs/9699919799/ for fork(); I can see why it
would be difficult to get child processes correct. There seem to be a number
of optional portions, which suggests that different implementations of fork()
will yield different results. Garrett is right; aborting is probably the best
way to go.
Thanks,
Cem Karan
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
- References:
- [nanomsg] On pthread_atfork(), and fork()-safe implementation
- [nanomsg] Re: On pthread_atfork(), and fork()-safe implementation
- [nanomsg] Re: On pthread_atfork(), and fork()-safe implementation
- [nanomsg] Re: On pthread_atfork(), and fork()-safe implementation
- [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation
- From: Karan, Cem F CIV USARMY RDECOM ARL (US)
- [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation
- [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation
- [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation
- From: Karan, Cem F CIV USARMY RDECOM ARL (US)
- [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation
- [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation
- From: Karan, Cem F CIV USARMY RDECOM ARL (US)
- [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation
- [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation
Other related posts:
- » [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation- Karan, Cem F CIV USARMY RDECOM ARL (US)
- » [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation- Michael Powell
- » [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation- Garrett D'Amore
- » [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation- Karan, Cem F CIV USARMY RDECOM ARL (US)
- » [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation- Garrett D'Amore
- » [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation- Karan, Cem F CIV USARMY RDECOM ARL (US)
- » [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation- Garrett D'Amore
- » [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation- Franklin Mathieu
- » [nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation - Karan, Cem F CIV USARMY RDECOM ARL (US)