Pre- and post-execution processing behavior

Pre- and post-execution processing applies to both UNIX and Windows hosts.

Host type

Environment

UNIX

  • The pre- and post-execution commands run in the /tmp directory under /bin/sh -c, which allows the use of shell features in the commands. The following example shows valid configuration lines: PRE_EXEC= /usr/share/lsf/misc/testq_pre >> /tmp/pre.out POST_EXEC= /usr/share/lsf/misc/testq_post | grep -v "Testing..."

  • LSF sets the PATH environment variable to PATH='/bin /usr/bin /sbin /usr/sbin'

  • The stdin, stdout, and stderr are set to /dev/null

Windows

  • The pre- and post-execution commands run under cmd.exe /c

  • The standard input, standard output, and standard error are set to NULL

  • The PATH is determined by the setup of the LSF Service


Note:

If the pre-execution or post-execution command is not in your usual execution path, you must specify the full path name of the command.

Order of command execution

Pre-execution commands run in the following order:
  1. The queue-level command

  2. The application-level or job-level command. If you specify a command at both the application and job levels, the job-level command overrides the application-level command; the application-level command is ignored.


If a pre-execution command is specified at the …

Then the commands execute in the order of …

Queue, application, and job levels

  1. Queue level

  2. Job level

Queue and application levels

  1. Queue level

  2. Application level

Queue and job levels

  1. Queue level

  2. Job level

Application and job levels

  1. Job level


Post-execution commands run in the following order:
  1. The application-level command

  2. The queue-level command

  3. The job-level command

If both application-level (POST_EXEC in lsb.applications) and job-level post-execution commands are specified, job level post-execution overrides application-level post-execution commands.

If a post-execution command is specified at the …

Then the commands execute in the order of …

Queue, application, and job levels

  1. Job level

  2. Queue level

Queue and application levels

  1. Application level

  2. Queue level

Queue and job levels

  1. Job level

  2. Queue level


Pre-execution command behavior

A pre-execution command returns information to LSF by means of the exit status. LSF holds the job in the queue until the specified pre-execution command returns an exit code of zero (0). If the pre-execution command exits with a non-zero value, the job pends until LSF tries again to dispatch it. While the job remains in the PEND state, LSF dispatches other jobs to the execution host.

If the pre-execution command exits with a value of 99, the job exits without pending. This allows you to cancel the job if the pre-execution command fails.

You must ensure that the pre-execution command runs without side effects; that is, you should define a pre-execution command that does not interfere with the job itself. For example, if you use the pre-execution command to reserve a resource, you cannot also reserve the same resource as part of the job submission.

LSF users can specify a pre-execution command at job submission. LSF first finds a suitable host on which to run the job and then runs the pre-execution command on that host. If the pre-execution command runs successfully and returns an exit code of zero, LSF runs the job.

Post-execution command behavior

A post-execution command runs after the job finishes, regardless of the exit state of the job. Once a post-execution command is associated with a job, that command runs even if the job fails. You cannot configure the post-execution command to run only under certain conditions.

The resource usage of post-execution processing is not included in the job resource usage calculation, and post-execution command exit codes are not reported to LSF.

If POST_EXEC=$USER_POSTEXEC in either lsb.applications or lsb.queues, UNIX users can define their own post-execution commands:
setenv USER_POSTEXEC /path_name
where the path name for the post-execution command is an absolute path.

If POST_EXEC=$USER_POSTEXEC and …

Then …

The user defines the USER_POSTEXEC environment variable

  • LSF runs the post-execution command defined by the environment variable USER_POSTEXEC

  • After the user-defined command runs, LSF reports successful completion of post-execution processing

  • If the user-defined command fails, LSF reports a failure of post-execution processing

The user does not define the USER_POSTEXEC environment variable

  • LSF reports successful post-execution processing without actually running a post-execution command


Important:

Do not allow users to specify a post-execution command when the pre- and post-execution commands are set to run under the root account.