5.1.7 Execution as a separate process
If the following formats appear in a job definition script, execution takes place in a different process from the current process. A change made by another process is not inherited to the current process.
Format |
Location where details are described |
---|---|
command_1 | command_2 |
|
$(command) , ` command ` |
|
(command) |
|
command & |
|
command |& |
An example of execution in another process is shown in the following.
- Executing a separate process by using a pipe (|):
The handling of execution in a separate process using a pipe (|) depends on the PIPE_CMD_LAST parameter specification.
- Example:
hostname | read STR
- When CURRENT is specified in the PIPE_CMD_LAST parameter
The hostname command is executed in a separate process, but the read command is executed in the current process.
- When OTHER is specified in the PIPE_CMD_LAST parameter
The hostname and read commands are both executed in a separate process. Therefore, the result of the hostname command is not assigned to the STR variable.
- Executing a separate process by using command substitution ($(), ``):
- Example:
$(date '+%Y%m%d') # Execute a command whose name is the output result of the date command `date '+%Y%m%d'` # Execute a command whose name is the output result of the date command
- Executing a background process by using |&:
- Example:
echo abc |& # Output the character string abc by a background process sleep 1 read -p STR # Read the data that was output by the background process echo $STR
- Executing grouped commands in a subshell:
- Example:
(TZ=GMT; export TZ; date) # Convert the TZ environment variable temporarily # to GMT and then output the time
- Background execution by using &:
- Example:
sleep 10 &
Replacement of character strings is performed in a separate process. Therefore, if the character string assigned to a variable by using one of the above formats is executed as a command, the variable name before substitution is output to the command execution results in the job execution log file. However, for aliases, the command name obtained after the alias was resolved is output because the alias is resolved in the current process before it is executed.
- Contents of the job definition script:
ls="ls -lt" # Assign "ls -lt" to variable ls alias gt="grep test" # Define "grep test" for alias gt $ls | gt # Execute ls -lt | grep test
- Contents of the job execution log file for the executed job
******** JOB CONTROLLER MESSAGE ******** 16:01:11 152286 KNAX0091-I ADSH152286 The job started. 16:01:11 152286 KNAX7901-I The adshexec command will wait for all asynchronous processes at the end of the job. 16:01:11 152286 KNAX7902-I The adshexec command will run in tty stdin mode. 16:01:11 152286 KNAX6110-I Execution of the command ls=ls -lt (line=1) finished successfully. exit status=0 execution time=0.000s CPU time=0.000s 16:01:11 152286 KNAX6112-I Execution of the command alias (line=2) finished successfully. exit status=0 execution time=0.000s CPU time=0.000s 16:01:11 152286 KNAX6116-I Execution of the command $ls (line=3) finished successfully. exit status=0 execution time=0.002s CPU time=0.000s 16:01:11 152286 KNAX6116-I Execution of the command /opt/jp1as/cmd/grep (line=3) finished successfully. exit status=0 execution time=0.001s CPU time=0.000s 16:01:11 152286 KNAX0098-I ADSH152286 The job ended. exit status=0 execution time=0.007s CPU time=0.000s
To enable specification of the #-adsh_rc_ignore command for a command specified in the above format, you must specify the base name of the character string before replacement as the command name in the argument of the #-adsh_rc_ignore command.
Do not execute the following commands as a separate process:
Type |
Command |
---|---|
Shell operation command |
adshfile |
adshmsvcd [only for Windows] |
|
adshmsvce [only for Windows] |
|
adshmdctl [only for UNIX] |
|
Extended shell command |
adshecho |
adshread |
|
adshjoberr |
|
adshcmdrc |
|
Extended script command |
All |
Difference between Windows version and UNIX version
When using the following command as a different process, execution of process varies between the Windows version and the UNIX version.
-
Standard shell commands
-
Script control statement
-
Extended shell command
-
Reserved script command
-
Substitution expression
-
Function
-
Command including command substitution (example: cmdA $(cmdB) (making cmdA and cmdB as external commands))
-
In the following cases, the defined alias will be used in other processes.
If you do not want to substitute arguments with the defined alias, enclose the command name in quotation marks (' or ").
Case 1
When all of the following conditions are met:
-
A script that was read before the alias was defined is executed in another process.
-
The alias is defined.
-
The defined alias is to be used to replace an argument of a command executed in another process.
For example:
fn(){ (ahost) #Condition 3 } alias ahost='hostname' #Condition 2 fn #Condition 1
Case 2
When all of the following conditions are met:
-
The alias is defined in another process.
-
The defined alias is to be used to replace an argument of a command executed in the process described in condition 1.
For example:
(alias ahost='hostname' #Condition 1 ahost) #Condition 2
-
Differences between the execution of different processes of the UNIX version and the Windows version are as follows:
-
If an error occurs in a different process while the root job is in the extended output mode, error information is output to the standard error output. The file name and line number are not output to the error information.
-
When executing a child job as a different process, behavior of the child job may become the same as when DELETE is specified for the SPOOLJOB_CHILDJOB parameter.
-
Different processes use the settings of the environment file. Therefore, if you start a different process when specifying the relative path name for the environment variable ADSH_ENV while the current directory is being moved, the different process will terminate with an error because the environment file cannot be read.
-
When executing a function as a different process, the array of the function call line number array of later function information arrays becomes the line number where the function is executed as a different process.
-
The file descriptor is not inherited to the different process and the different process will close. For example, an error will occur if, in the script being executed as a different process, an input or output is performed without the different process reopening the parent process in relation to the file descriptor in which the parent process is being opened. Standard output and standard error output are open again.
-
The different processes operate in the minimum output mode. For the reason, the different processes do not display the information message and output destination of error messages is in accordance with the minimum output mode.
-
Different processes operate while NO is specified for the SPOOLJOB_CREATE parameter. For the behavior while NO is specified for the SPOOLJOB_CREATE parameter, see (a) Determining whether the spool job creation suppression functionality is to be used.
-
The variable that is specified by the #-adsh_path_var command is not defined as the variable handling the path in the different process. If you define the variable handling the path in the different process, specify the variable by using the PATH_CONV_VAR parameter and the PATH_CONV_NOVAR parameter.
- Important
When the following standard shell commands are executed in a separate process, whether execution of the command results in normal termination or error termination differs from when these commands are executed in the current process, as described in the following:
let command
If this command is executed in a separate process without an arithmetic expression specified, it terminates normally with return code 1.
exit and return commands
If either of these commands is executed in a separate process with a non-numeric value specified in its argument, it terminates normally with return code 1.
getopts command
If this command is executed in a separate process and the end of options is detected, the command terminates with an error with return code 1. Use the successRC attribute of the #-adsh_step_start command or the #-adsh_rc_ignore command to make sure that the getopts command will not terminated with an error.
read command
If this command is executed in a separate process and detects an end-of-file (EOF), it terminates with an error with return code 1. You can prevent such a termination with an error by using the successRC attribute of the #-adsh_step_start or #-adsh_rc_ignore command.
In the UNIX edition, if this command is executed as a separate process and that process receives a termination request signal, execution of the command might continue in the separate process depending on the type of signal. To forcibly terminate processing of the command as a separate process, send SIGTERM to that process.