The spawn callable service combines the semantics of the fork and exec callable services to create a child process to run a specified z/OS UNIX executable file.
Operation | Environment |
---|---|
Authorization: | Supervisor or problem state, any PSW key, any TCB key |
Dispatchable unit mode: | Task |
Cross memory mode: | PASN = HASN |
AMODE (BPX1SPN): | 31-bit |
AMODE (BPX4SPN): | 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 BPX4SPN with the same parameters. All parameter addresses and addresses in parameter structures are doublewords.
The name of a fullword that contains the length of the path name of the file. The length of the path name can be up to 1023 bytes.
The name of a field that contains the fully qualified path name of the file that is to be run. Each component of the path name (directory name, subdirectory name, or file name) can be up to 255 characters long. The complete path name can be up to 1023 characters long, and does not require an ending NUL character.
The name of a fullword that contains the number of pointers in the lists for the Argument_length_list and the Argument_list. If the program needs no arguments, specify 0.
The name of a list of 31(64)-bit pointers. Each pointer in the list is the 31(64)-bit address of a fullword that gives the length of an argument that is to be passed to the specified program. If the program needs no arguments, define Argument_length_list as the name of a fullword (doubleword) that contains 0.
If the target executable file arguments require null terminators, the arguments that are supplied to this service must include the null terminator as part of the data string and the length.
The name of a list of 31(64)-bit pointers. Each pointer in the list is the 31(64)-bit address of a character string that is an argument to be passed to the specified program. Each argument is of the length that is specified by the corresponding element in the Argument_length_list. If the program needs no arguments, define Argument_list as the name of a fullword (doubleword) that contains 0.
The name of a fullword that contains the number of pointers in the lists for Environment_data_length and Environment_data_list. If the program needs no environment data, specify 0.
The name of a list of 31(64)-bit pointers. Each 31(64)-bit pointer in the list is the 31(64)-bit address of a fullword that gives the length of an environment variable that is to be passed to the specified program. If the program does not use environment variables, specify 0.
The name of a list of 31(64)-bit pointers. Each 31(64)-bit pointer in the list is the 31(64)-bit address of a character string that is an environment variable to be passed to the specified program. Each environment variable is of the length that is specified by the corresponding element in Environment_data_length. If the program does not use environment variables, specify 0.
If the target executable file is an IBM® Language Environment®-enabled program, the environment variables that are supplied to this service must include the null terminator as part of the data string and length. Trailing blanks can cause the environment variable to be processed incorrectly. Each environment variable is searched for a null character; if a null character is found, the environment variable is truncated at that point.
The name of a fullword that contains the number of file descriptors the child process is to inherit. It may take values from 0 to OPEN_MAX. If the value is 0, all file descriptors from the parent are inherited without remapping by the child, and the filedesc_list is ignored.
The name of an array of fullword file descriptor remap values that indicate how the child's file descriptors are to be remapped from the caller's (parent's) file descriptors. Except for those file descriptors that are designated by SPAWN_FDCLOSED in the supplied array, each of the child's file descriptors in the range zero to Filedesc_count-1 inherits file descriptor remap values filedesc_list(1) to filedesc_list(filedesc_count) from the supplied file descriptor array. The constant SPAWN_FDCLOSED is defined in the BPXYCONS macro.
As an example, assume that the caller supplies an array of 3 entries with the values 7, 5, and 4 respectively. This causes the child's file descriptor 0 to be remapped to the parent's file descriptor 7, the child's file descriptor 1 to be remapped to the parent's file descriptor 5, and the child's file descriptor 2 to be remapped to the parent's file descriptor 4.
The name of a fullword that contains the length of the inheritance structure that is to follow. If this parameter contains a value of zero, the Inherit_area parameter is ignored.
The name of a data area that contains the inheritance structure for the child process. See the BPXYINHE mapping for the details of the inheritance structure (BPXYINHE — Spawn Inheritance Structure).
The name of a fullword in which the spawn service returns the process ID of the newly created child process, or -1 if it is not successful.
Return_code | Explanation |
---|---|
EACCES | The caller does not have appropriate permissions to run the specified file. It may lack permission to search a directory that is named in the Pathname parameter; it may lack execute permission for the file to be run; or the file to be run is not a regular file and the system cannot run files of its type. |
EAGAIN | The resources that are required to let another process be created are not available now; or you have already reached the maximum number of processes or UIDs that you are allowed to create. This error is also generated if _BPX_USERID was specified, and the specified user name was not defined to SAF with an OMVS segment. The following reason codes can accompany the return code: JROK, JRMaxUIDs or JRWlmWonErr. |
EBADF | An entry in the filedesc_list is not a valid file descriptor; or the controlling terminal file descriptor that was specified in the inheritance structure is not valid. |
EINVAL | One or more of the following conditions were detected:
|
ELOOP | A loop exists in symbolic links that were encountered during resolution of the Filename argument. This error is issued if more than 24 symbolic links are detected in the resolution of Filename. |
EMVSERR | If EMVSERR is accompanied by reason code JrLocalSpawnNotAllowed,
it means that the parameters specify that a local process must be
created. It also means that one or more of the current address space's
attributes is to be changed. A spawn request is not allowed to change
certain attributes of the current address space. A spawn request
is required to create a local process when either the environment
variable _BPX_SHAREAS is set to MUST (_BPX_SHAREAS=MUST) or when the
inheritance structure in the parameter list specifies InheMustBeLocal.
When this reason code is given, the spawn request requires a local
process to be created and one or both of the following conditions
is also present:
|
EMVSSAF2ERR | The executable file is a set-user-ID or set-group-ID file and the file owner's UID or GID is not defined to the Security Access Facility (SAF). |
ENAMETOOLONG | File_name is longer than 1023 characters, or some component of the file name is longer than 255 characters. Name truncation is not supported. |
ENOENT | No file name was specified, or one or more of the components of the specified Filename were not found. |
ENOEXEC | The specified file has execute permission, but it is not in the proper format to be a process image file. Reason_code contains the loader reason code for the error. |
ENOMEM | The new process requires more memory than is permitted by the hardware or the operating system. |
ENOTDIR | A directory component of Filename is not a directory. |
ENOTTY | The tcsetpgrp failed for the specified controlling terminal file descriptor in the inheritance structure. The failure occurred because the calling process does not have a controlling terminal, or the specified file descriptor is not associated with the controlling terminal, or the controlling terminal is no longer associated with the session of the calling process. |
EPERM | The spawn failed for one of the following reasons:
|
ESRCH | The specified process group ID in the inheritance structure is not that of a process group in the calling process's session. |
Reason code | Explanation |
---|---|
X'xxxx0C27' | The target z/OS UNIX file is not in the correct format to be an executable file. |
X'xxxx0C31' | The target z/OS UNIX file is built at a level that is higher than that supported by the running system. |
For AMODE 31 callers, the high-order bit in the last parameter address is 1. For AMODE 64 callers, the high-order bit is part of the 64-bit address. There are always n parameters, passed with no end-of-parameter-list indicator.
The last parameter that spawn passes to the executable file identifies the caller of the file as the exec or spawn service.
If the STEPLIB environment variable is not specified, the default behavior of the spawn service is the same as if STEPLIB=CURRENT were specified.
If the program that is to be invoked is a set-user-ID or set-group-ID file, and the user-ID or group-ID of the file is different from that of the current process image, the data sets that are to be built into the STEPLIB environment for the new process image must be found in the system sanction list for set-user-id and set-group-id programs. Only those data sets that are found in the sanction list are built into the STEPLIB environment for the new process image. See Using sanction lists in z/OS UNIX System Services Planning for detailed information about the sanction list. See Tuning performance in z/OS UNIX System Services Planning for information about STEPLIB performance considerations.
Note that only one local spawned process per TSO address space is supported at a given time. This is done to reduce conflict among multiple shells running in the same address space.
In this case, the spawn service behaves as follows:
The fourth through the last arguments in the list are to contain the list of arguments specified by the caller of the spawn service.
#! Path String
#! is the file magic number. It identifies the first line of the file as a special header that contains the name of the program to be run and any argument data to be supplied to it.
The Path parameter specifies the path name of the file that is to be run. It is separated by blank or tab characters from the #! characters, or can immediately follow the characters.
The String parameter is an optional character string that can be used to pass options to a target command interpreter (shell) that is to run the script. It must be separated from the Path parameter by tab or blank characters, and cannot itself contain tab or blank characters.
The remaining arguments in the list are to contain the list of arguments specified by the caller of the spawn service.
If the path name that is specified in the magic number header cannot be executed for some reason, the spawn request fails with return code ENOEXEC, regardless of the error. ENOEXEC is returned for compatibility purposes, so that existing scripts can continue to run successfully when invoked from an application such as a command interpreter (shell). The reason code indicates the exact reason the magic number file could not be executed.
The file that is used to capture messages can be changed at any time by calling the oe_env_np service and specifying _BPXK_JOBLOG with a different file descriptor.
Message capturing is turned off if the specified file descriptor is marked for close on a fork or exec.
Message capturing is process-related. All threads under a given process share the same job log file. Message capturing may be initiated by any thread under that process.
Multiple processes in a single address space can each have different files active as the JOBLOG file; some or all of them can share the same file; and some processes can have message capturing active while others do not.
When the file that is used as a job log is shared by several processes (for example, by a parent and child), the file should be opened for append. Failure to do this causes unpredictable results.
Only files that can be represented by file descriptors may be used as job log files; MVS data sets are not supported.
Message capturing is propagated on a fork() or spawn(). If a file descriptor is specified, the physical file must be the same in order for message capturing to continue in the forked or spawned process. If STDERR is specified, the file descriptor may be remapped to a different physical file.
Message capturing may be overridden on exec() or spawn() by specifying the _BPXK_JOBLOG environment variable as a parameter on the exec() or spawn().
Message capturing only works in forked (BPXAS) address spaces.
This is not true joblog support: messages that would normally go to the JESYSMSG data set are captured, but messages that go to JESMSGLG are not.
BPXYINHE field | Authority required |
---|---|
INHEUSERID | The caller must have daemon authority. See Giving daemon authority to vendor-written programs in z/OS UNIX System Services Planning for information about setting up daemon authority for a user. |
INHEREGIONSZ | When the new region size is smaller than the caller's current hard limit for RLIMIT_AS, no authorization is required. To exceed the current hard limit, the caller must have superuser authority (UID=0), or the spawn function will fail. |
INHETIMELIMIT | When the new CPU time limit is less than the caller's current hard limit for RLIMIT_CPU, no authorization is required. To exceed the current hard limit, the caller must have superuser authority (UID=0), or the spawn function will fail. |
INHEUMASK | The caller must have superuser authority to set the child's file mode creation mask, or the spawn function will fail. |
INHECWD | The caller must have superuser authority to set the child's current working directory, or the spawn function will fail. |
For an example using this callable service, see BPX1SPN (spawn) example.