Hitachi

Job Management Partner 1 Version 10 Job Management Partner 1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide


trap command (specifies the action when signals and forced termination requests are received)

The functionality of the trap command for the Windows edition differs from its functionality for the UNIX edition. For details about the functionality for the UNIX edition, see (1) trap command (UNIX edition). For details about the functionality for the Windows edition, see (2) trap command (Windows edition).

(1) trap command (UNIX edition)

Organization of this page

Format

trap  [action] [signal ...]

Description

This command specifies the action to be taken when one or more specified signals are received. When the shell receives a specified signal, it executes the specified action.

When this command is executed with no arguments, it outputs to the standard output a list of the actions associated with all signals in the following format:

Category of signal

Output format

Signal whose name is defined

trap -- action signal-name-without-SIG-prefix

Signal whose name is not defined

trap -- action UNKNOWN SIGNAL

Actions can be set for signals for which multiple names are defined under a single signal number, as shown in the tables below.

Linux

Signal name

Alternate name

Whether an action can be set by the trap command

SIGSYS

SIGUNUSED

SIGSYS

Can be set.

SIGUNUSED

Can be set.

Note:

Because extended functions use SIGSYS, not SIGUNUSED, as the main signal name, the trap command also treats SIGSYS as the signal name.

AIX

Signal name

Alternate name 1

Alternate name 2

Whether an action can be set by the trap command

SIGABRT

SIGLOST

SIGIOT

SIGABRT

Can be set.

SIGLOST

Can be set.

SIGIOT

Can be set.

SIGIO

SIGPOLL

None

SIGIO

Can be set.

SIGPOLL

Can be set.

HP-UX or Solaris

Signal name

Alternate name

Whether an action can be set by the trap command

SIGABRT

SIGIOT

SIGABRT

Can be set.

SIGIOT

Can be set.

SIGIO

SIGPOLL

SIGIO

Can be set.

SIGPOLL

Can be set.

When an action is specified for a signal for which multiple names are defined under a single signal number, one of the specified signal names is output.

The trap command does not display an action that is set for a signal when that action is registered in an extended function.

Arguments

action

Specifies the action to be taken when the specified signals are received. If this argument is omitted or a hyphen (-) is specified, the previously-specified traps for the specified signals are reverted to their default settings. If action is omitted and a signal number is specified for signal, the previously specified traps for the specified signals are also reverted to their default settings.

signal

Specifies a signal that is to be trapped. You can specify a signal number or a signal name. When you specify a signal name, you must specify it without the leading SIG (for example, specify INT for SIGINT). For the specifications for each signal, see the documentation for the OS being used.

The operation that is performed when SIGTERM is specified depends on the specification of the TRAP_ACTION_SIGTERM environment setting parameter. For details, see TRAP_ACTION_SIGTERM parameter (defines the job controller's action when a forced termination request is received) in 7. Parameters Specified in the Environment Files.

You can specify multiple signals delimited by the space. You can also specify 0, EXIT, or ERR for this argument.

When you execute the trap command with 0 or EXIT specified for signal

Executes the command specified in action when the shell terminates.

When you execute the trap command with ERR specified for signal

Executes the action specified in action when the any of the following commands executed after the trap command terminates with a non-zero return code:

  • Regular built-in command

  • typeset command

  • return command that results in an error in a function or external script because of an invalid format

In AIX, the SIGWAITING signal cannot be specified. If you execute this command in AIX with SIGWAITING specified, the command terminates with an error.

Return codes

Return code

Meaning

0

Normal termination

1

Error termination

Notes

Usage examples

(2) trap command (Windows edition)

Format

trap [action][method]

Description

This command specifies the action to be taken when a forced termination request is received.

When TERM is specified in the TRAP_ACTION_SIGTERM parameter

The action to be taken upon receiving a forced termination request can be specified. When the forced termination request specified in the method is received, the job controller performs the operation specified for action.

If the forced termination request specified in method is neither TERM nor 15, the command issues the KNAX6718-I message and terminates with return code 0 without performing the specified action.

If the command is executed with no argument specified, it outputs the action set for forced termination requests to the standard output in the following format:

Output format

trap -- action "character-string-indicating-the-forced-termination-method"

When DISABLE is specified in the TRAP_ACTION_SIGTERM parameter

The command issues the KNAX6710-I message and always terminates normally with return code 0. The command does not perform processing for forced termination requests.

Arguments

action

Specifies the action to be taken when a forced termination request is received.

If a hyphen (-) is specified for action,the command resets the previously specified action setting for the specified method so that the method is not associated with any action setting. If action is omitted and 15 is specified in the method argument, the command also resets the previously specified action setting for the specified method so that the method is not associated with any action setting.

If you specify "" for the action, the trap command terminates normally without changing the current setting for action.

method

Specifies the forced termination method that is to be subject to the trap.

You must specify either TERM or 15 for method.

TERM or 15

Specifies that immediate process termination is to be performed by a function such as TerminateProcess (such as forced termination from JP1/AJS or the taskkill command).

Return codes

Return code

Meaning

0

Normal termination

1

Error termination

Notes

Usage Examples