The fork callable service creates a new process, called a child process.
Operation | Environment |
---|---|
Authorization: | Supervisor state or problem state, PSW key 8, TCB key 8. |
Dispatchable unit mode: | Task |
Cross memory mode: | PASN = HASN |
AMODE (BPX1FRK): | 31-bit |
AMODE (BPX4FRK): | 64-bit |
ASC mode: | Primary mode |
Interrupt status: | Enabled for interrupts |
Locks: | Unlocked |
Control parameters: | All parameters must be addressable by the caller and in the primary address space. |
|
AMODE 64 callers use BPX4FRK with the same parameters.
The name of a fullword in which the fork service places the process ID of the newly created child process, 0, or -1.
Upon successful completion, fork returns the process ID of the newly created child to the calling (parent) process.
Because the child is a duplicate, it contains the same service request to the fork service as the parent. Execution of the child begins with this fork service returning a process ID value of zero; the child then proceeds with normal execution.
If Process_ID is returned as -1, no child process was created, for the reason shown by Return_code.
Return_code | Explanation |
---|---|
EAGAIN | The resources required to let another process be created are
not available now; or you have already reached the maximum number
of processes you are allowed to run. The following reason codes can accompany the return code: JRForkExitRcChildNoStorage, JRForkExitRcParentBadEnv, JRForkExitRcParentNoRoom, JRForkNoAccess, JRForkNoResource, JRForkVsmListTooLarge, JRKernelReady, JRMaxChild, JRMaxProc, JRMaxUIDs, JRNoSecurityProduct, JRNotKey8, and JRWlmWonErr. |
EINVAL | The following reason code can accompany the return code: JRJsrRacXtr. |
ENOMEM | The process requires more space than is available. |
The name of a fullword where the fork service stores the reason code. The fork service returns Reason_code only if Return_value is -1. Reason_code further qualifies the Return_code value. For the reason codes, see z/OS UNIX System Services Messages and Codes.
In other respects, for z/OS UNIX the child is identical to the parent.
BPX1FRK only supports the propagation of key 8 storage; therefore, the fork service does not propagate to the child any shared memory segments that reside in a storage key other than key 8.
The child process inherits the MEMLIMIT of the parent.
When the fork service is called from a multiple-process address space, only storage obtained by the tasks in the calling process in the subpools identified previously are copied to the child address space.
If the parent was single-task with multiple RBs, only a single RB is created in the child address space after the fork service request. If multiple tasks exist in the parent process, only the task issuing the fork service request is replicated. There is no serialization among the different tasks.
For example, the task I/O table (TIOT) is not copied. This means that MVS data sets that were allocated in the parent are not allocated to the child, with the exception of the propagated TASKLIB, STEPLIB, or JOBLIB DD data sets. Because user data in user subpools are copied, it is possible that some of those control blocks can point to system control blocks that are no longer present in the child.
As another example, a user's data control block (DCB) that has been opened in the parent still appears as an opened DCB in the child, but the corresponding system control blocks pointed to by the DCB are not present in the child.
Only services that are specifically documented as supported can be used across the fork service. For further details, see "MVS-related information" in this topic.
For an example using this callable service, see BPX1FRK (fork) example.
If a supervisor state parent process issues a LOAD macro for a module, the child process cannot issue a DELETE macro for the module, and it cannot use a LOAD macro to load a new copy of the module.
A LOAD macro for global storage, however, is not reflected in the child; the child cannot issue a DELETE macro to remove a module that was loaded to a common storage by the parent.
If the ThliForkAcctg bit is set on in BPXYTHLI — Thread-level information, the fork service creates the child with the accounting data from the RACF® WORKATTR of the user ID that is associated with the last setuid call. If no setuid call has been performed, the accounting information from the parent is used. No error is returned to the caller.