On Tue, 13 Nov 2001, Jonathan Leffler wrote:
>CHEN SEI-LIM wrote:
>> Jonathan Leffler wrote:
>> > CHEN SEI-LIM wrote:
>> > > You can make a simple program to try it not only your supposition.
>> > > If I am wrong I will say sorry to everybody.
>> >
>> > Since you're so adamant that it can be done, perhaps you'd care to
>> > show us the code that allows it to work [...]
>>
>> In UNIX, child inherit every thing from parent but PID after forking.
>> The same stack, heap, text, and file discriptors.
>
>In POSIX.1-1990 (which is what I have at home; I keep the 1996 standard
>at work), there are 8 items that are different between the child and
>the parent:
>
>1. The child process has a unique process ID. The child's PID also
> does not match any active process group ID.
>
>2. The child process has a different parent process ID (which is the
> process ID of the parent process).
>
>3. The child process has its own copy of the parent's file descriptors.
> Each of the childs file descriptors refers to the the same open file
> description with the corresponding file descriptor of the parent.
>
>[JL note snipped]
>
>4. The child process has its own copy of the parent's open directory
> streams.
>
>5. The child process's values of tms_utime, tms_stime, tms_cutime and
> tms_cstime are set to zero.
>
>6. File locks previously set by the parent are not inherited by the
> child.
>
>7. Pending alarms are cleared for the child process.
>
>8. The set of signal pending for the child process is initialized to
> the empty set.
>
>I'm pretty sure that there are a whole bunch of extra small details
>that are different in the current POSIX.1-1996 standard.
And POSIX.1-1996 adds another 8 items:
9. If semaphores are supported, semaphores that are open in the parent
process are also open in the child.
10. If process memory locking is supported, the process shall not
inherit any address space memory locks established by the parent.
11. If Memory Mapped Files or Shared Memory Objects are supported,
memory mappings created in the parent shall be visible in the child.
12. If Process Scheduling is supported, then [...blah about inheriting
scheduling...]
13. If the timers option is supported, per process timers created by the
parent are not inherited by the child process.
14. If the Message Passing option is supported, the child process has
its own copy of the message queue descriptors of the parent.
15. If the Asynchronous I/O option is supported, no async i/o ops are
inherited by the child process.
16. A process is created with a single thread. If a multithreaded
process calls fork(), the new process shall contain a replica of the
calling thread and its entire address space, possibly including the
states of mutexes and other resources. Consequently, to avoid
errors, the child process may only execute async-signal safe
operations until such time as one of the exec functions is called.
If {_POSIX_THREADS} is defined, fork handlers may be established by
means of the pthread_atfork() function in order to maintain
application invariants across fork() calls.
There's also a comment immediately after this list "The inheritance of
process characteristics not defined by [POSIX.1] should be documented in
the system documentation."
>[...mega-snip of material expounding why simply having the same file
>descriptors/sockets open in both parent and child does not guarantee
>that everything will work sanely...]
--
Jonathan Leffler #include <disclaimer.h>
STSM, IBM Data Management Solutions. Phone: +1 650-926-6921
Email: [EMAIL PROTECTED], [EMAIL PROTECTED]
Guardian of DBD::Informix v1.00.PC1 -- http://dbi.perl.org
"I don't suffer from insanity; I enjoy every minute of it!"