| 1 | $Id: Fork.os2 1281 2004-03-06 21:48:26Z bird $
|
|---|
| 2 |
|
|---|
| 3 | Fork Design Draft
|
|---|
| 4 | --------------------
|
|---|
| 5 |
|
|---|
| 6 | 1.0 Intro
|
|---|
| 7 | ----------
|
|---|
| 8 |
|
|---|
| 9 | blah.
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | 1.1 The SuS fork() Description
|
|---|
| 13 | ------------------------------
|
|---|
| 14 |
|
|---|
| 15 | NAME
|
|---|
| 16 |
|
|---|
| 17 | fork - create a new process
|
|---|
| 18 |
|
|---|
| 19 | SYNOPSIS
|
|---|
| 20 |
|
|---|
| 21 | #include <unistd.h>
|
|---|
| 22 |
|
|---|
| 23 | pid_t fork(void);
|
|---|
| 24 |
|
|---|
| 25 | DESCRIPTION
|
|---|
| 26 |
|
|---|
| 27 | The fork() function shall create a new process. The new process (child process) shall be an exact copy of the calling process (parent process) except as detailed below:
|
|---|
| 28 |
|
|---|
| 29 | * The child process shall have a unique process ID.
|
|---|
| 30 | * The child process ID also shall not match any active process
|
|---|
| 31 | group ID.
|
|---|
| 32 | * The child process shall have a different parent process ID,
|
|---|
| 33 | which shall be the process ID of the calling process.
|
|---|
| 34 | * The child process shall have its own copy of the parent's file
|
|---|
| 35 | descriptors. Each of the child's file descriptors shall refer
|
|---|
| 36 | to the same open file description with the corresponding file
|
|---|
| 37 | descriptor of the parent.
|
|---|
| 38 | * The child process shall have its own copy of the parent's open
|
|---|
| 39 | directory streams. Each open directory stream in the child process
|
|---|
| 40 | may share directory stream positioning with the corresponding
|
|---|
| 41 | directory stream of the parent.
|
|---|
| 42 | * [XSI] The child process shall have its own copy of the parent's
|
|---|
| 43 | message catalog descriptors.
|
|---|
| 44 | * The child process' values of tms_utime, tms_stime, tms_cutime, and
|
|---|
| 45 | tms_cstime shall be set to 0.
|
|---|
| 46 | * The time left until an alarm clock signal shall be reset to zero,
|
|---|
| 47 | and the alarm, if any, shall be canceled; see alarm() .
|
|---|
| 48 | * [XSI] All semadj values shall be cleared.
|
|---|
| 49 | * File locks set by the parent process shall not be inherited by
|
|---|
| 50 | the child process.
|
|---|
| 51 | * The set of signals pending for the child process shall be
|
|---|
| 52 | initialized to the empty set.
|
|---|
| 53 | * [XSI] Interval timers shall be reset in the child process.
|
|---|
| 54 | * [SEM] Any semaphores that are open in the parent process shall
|
|---|
| 55 | also be open in the child process.
|
|---|
| 56 | * [ML] The child process shall not inherit any address space memory
|
|---|
| 57 | locks established by the parent process via calls to mlockall()
|
|---|
| 58 | or mlock().
|
|---|
| 59 | * [MF|SHM] Memory mappings created in the parent shall be retained
|
|---|
| 60 | in the child process. MAP_PRIVATE mappings inherited from the
|
|---|
| 61 | parent shall also be MAP_PRIVATE mappings in the child, and any
|
|---|
| 62 | modifications to the data in these mappings made by the parent
|
|---|
| 63 | prior to calling fork() shall be visible to the child. Any
|
|---|
| 64 | modifications to the data in MAP_PRIVATE mappings made by the
|
|---|
| 65 | parent after fork() returns shall be visible only to the parent.
|
|---|
| 66 | Modifications to the data in MAP_PRIVATE mappings made by the
|
|---|
| 67 | child shall be visible only to the child.
|
|---|
| 68 | * [PS] For the SCHED_FIFO and SCHED_RR scheduling policies, the
|
|---|
| 69 | child process shall inherit the policy and priority settings
|
|---|
| 70 | of the parent process during a fork() function. For other s
|
|---|
| 71 | cheduling policies, the policy and priority settings on fork()
|
|---|
| 72 | are implementation-defined.
|
|---|
| 73 | * [TMR] Per-process timers created by the parent shall not be
|
|---|
| 74 | inherited by the child process.
|
|---|
| 75 | * [MSG] The child process shall have its own copy of the message
|
|---|
| 76 | queue descriptors of the parent. Each of the message descriptors
|
|---|
| 77 | of the child shall refer to the same open message queue
|
|---|
| 78 | description as the corresponding message descriptor of the parent.
|
|---|
| 79 | * [AIO] No asynchronous input or asynchronous output operations
|
|---|
| 80 | shall be inherited by the child process.
|
|---|
| 81 | * A process shall be created with a single thread. If a
|
|---|
| 82 | multi-threaded process calls fork(), the new process shall contain
|
|---|
| 83 | a replica of the calling thread and its entire address space,
|
|---|
| 84 | possibly including the states of mutexes and other resources.
|
|---|
| 85 | Consequently, to avoid errors, the child process may only execute
|
|---|
| 86 | async-signal-safe operations until such time as one of the exec
|
|---|
| 87 | functions is called. [THR] Fork handlers may be established by
|
|---|
| 88 | means of the pthread_atfork() function in order to maintain
|
|---|
| 89 | application invariants across fork() calls.
|
|---|
| 90 |
|
|---|
| 91 | When the application calls fork() from a signal handler and any of
|
|---|
| 92 | the fork handlers registered by pthread_atfork() calls a function
|
|---|
| 93 | that is not asynch-signal-safe, the behavior is undefined.
|
|---|
| 94 | * [TRC TRI] If the Trace option and the Trace Inherit option are
|
|---|
| 95 | both supported:
|
|---|
| 96 | If the calling process was being traced in a trace stream that
|
|---|
| 97 | had its inheritance policy set to POSIX_TRACE_INHERITED, the
|
|---|
| 98 | child process shall be traced into that trace stream, and the
|
|---|
| 99 | child process shall inherit the parent's mapping of trace event
|
|---|
| 100 | names to trace event type identifiers. If the trace stream in
|
|---|
| 101 | which the calling process was being traced had its inheritance
|
|---|
| 102 | policy set to POSIX_TRACE_CLOSE_FOR_CHILD, the child process
|
|---|
| 103 | shall not be traced into that trace stream. The inheritance
|
|---|
| 104 | policy is set by a call to the posix_trace_attr_setinherited()
|
|---|
| 105 | function.
|
|---|
| 106 | * [TRC] If the Trace option is supported, but the Trace Inherit
|
|---|
| 107 | option is not supported:
|
|---|
| 108 | The child process shall not be traced into any of the trace
|
|---|
| 109 | streams of its parent process.
|
|---|
| 110 | * [TRC] If the Trace option is supported, the child process of
|
|---|
|
|---|