The example program below runs a command on one of the best available hosts. It makes use of:
ls_rexecv() executes a program on the specified host. It does not return if successful. It returns ‑1 on failure.
ls_rexecv() is like a remote execvp. If a connection with the RES on a host has not been established, ls_rexecv() sets one up. The remote execution environment is set up to be exactly the same as the local one and is cached by the remote RES server. ls_rexecv() has the following parameters:
The options argument is constructed from the bitwise inclusive OR of zero or more or the option flags defined in <lsf/lsf.h> with names starting with ‘REXF_’. the group of flags are as follows:
Use a remote pseudo terminal as the stdin, stdout, and stderr of the remote task. This option provides a higher degree of terminal I/O transparency. This is needed only when executing interactive screen applications such as vi. The use of a pseudo-terminal incurs more overhead and should be used only if necessary. This is the most commonly used flag.
Use the local client’s current working directory as the current working directory for remote execution.
Request the remote RES to create a task port and return its number to the LSLIB.
Enable shell mode support if the REXF_USEPTY flag is also given. This flag is ignored if REXF_USEPTY is not given. This flag should be specified for submitting interactive shells, or applications which redefine, or applications which redefine the ctrl-C and ctrl-Z keys (e.g. jove).
LSLIB also provides ls_rexecve() to specify the environment to be set up on the remote host.
#include <stdio.h>#include <lsf/lsf.h>main(argc, argv)int argc;char *argv[];{char *command;char *resreq;char **best;int num = 1;/* check the input format */if (argc < 2 ) {fprintf(stderr, "Usage: %s command [argument ...]\n",argv[0]);exit(‑1);}command = argv[1];/* initialize the remote execution */if (ls_initrex(1, 0) < 0) {ls_perror("ls_initrex");exit(‑1);}/* get resource requirement for the given command */resreq = ls_resreq(command);best = ls_placereq(resreq, &num, 0, NULL);if (best == NULL) {ls_perror("ls_placereq()");exit(‑1);}/* start remote execution on the selected host for the job */printf("<<Execute %s on %s>>\n", command, best[0]);ls_rexecv(best[0], argv + 1, 0);/* if the remote execution is successful, the following lines will not be executed */ls_perror("ls_rexecv()");exit(‑1);}
The output of the above program would be something like:
The LSF command lsrun is implemented using the ls_rexecv() function. After remote task is initiated, lsrun calls the ls_rexecv() function, which then executes NIOS to handle all input/output to and from the remote task and exits with the same status when remote task exits.