Hitachi

JP1 Version 11 JP1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide 


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

(d) Pipes

$(command) , ` command `

(b) Command substitution

(command)

(10) Grouping commands

command &

(11) Other metacharacters

command |&

(a) Redirection

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.

Differences between the execution of different processes of the UNIX version and the Windows version are as follows:

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.