LSBLIB provides lsb_hostinfo() to get information about the server hosts in LSF batch. This includes configured static and dynamic information. Examples of host information include: host name, status, job limits and statistics, dispatch windows, and scheduling parameters.
The example program in this section uses lsb_hostinfo():
lsb_hostinfo() gets information about LSF batch server hosts. On success, it returns an array of hostInfoEnt structures which hold the host information and sets *numHosts to the size of the array. On failure, lsb_hostinfo() returns NULL and sets lsberrno to indicate the error.
lsb_hostinfo() has the following parameters:
To get information on all hosts, set *numHosts to 0. This sets *numHosts to the actual number of hostInfoEnt structures when lsb_hostinfo() returns successfully.
If *numHosts is 1 and hosts is NULL, lsb_hostinfo()returns information on the local host.
The hostInfoEnt structure is defined in lsbatch.h as
struct hostInfoEnt {char *host;int hStatus; Host statusint *busySched; Host loadSched busy reasonint *busyStop; Host loadStop busy reasonfloat cpuFactor;int nIdx; Number of load indexfloat *load; Load for scheduling batch jobsfloat *loadSched; Stop scheduling new jobs if overfloat *loadStop; Stop jobs if over this loadchar *windows; ASCII desp of run windowsint userJobLimit; Number of jobs per user allowed to runint maxJobs; Maximum number of jobs allowed to runint numJobs; Number of total jobsint numRUN; Number of running jobsint numSSUSP; Number of system suspended jobsint numUSUSP; Number of user suspended jobsint mig; Number of minutes suspended before migrationint attr; Host attributes#define H_ATTR_CHKPNTABLE 0x1#define H_ATTR_CHKPNT_COPY 0x2float *realLoad; Effective load of the hostint numRESERVE; Number of slots reserved for pending jobsint chkSig; If attr has an H_ATTR_CHKPNT_COPY attribute. chkSig is set to the signal which triggers checkpoint and copy operation. Otherwise, chkSig is set to the signal which triggers checkpoint operation on the hostfloat cnsmrUsage; Number of resources used by consumerfloat prvdrUsage; Number of resource used by providerfloat cnsmrAvail; Number of resources available for consumerfloat prvdrAvail; Number of resources available for providerfloat maxAvail; Maximum number of resources availablefloat maxExitRate; Job exit rate threshold on the hostfloat numExitRate; Number of job exit rate on the hostchar *hCtrlMsg; AdminAction - host control message};
There are differences between the host information returned by ls_gethostinfo() and the host information returned by the lsb_hostinfo(). ls_gethostinfo() returns general information about the hosts whereas lsb_hostinfo()returns LSF batch specific information about hosts.
For a complete description of the fields in the hostInfoEnt structure, see the lsb_hostinfo(3) man page.
The following example takes a host name as an argument and displays information about the named host. It is a simplified version of the LSF batch bhosts command.
/******************************************************* LSBLIB -- Examples** simbhosts* Display information about the batch server host with* the given name in the cluster.******************************************************/#include <lsf/lsbatch.h>int main (int argc, char *argv[]){struct hostInfoEnt *hInfo;/* array holding all job info entries */char *hostname = argv[1]; /* given host name */int numHosts = 1;/* number of interested host *//* check if input is in the right format: "./simbhostsHOSTNAME" */if (argc!=2) {printf("Usage: %s hostname\n", argv[1]);exit(-1);}/* initialize LSBLIB and get the configuration environment */if (lsb_init(argv[0]) < 0) {lsb_perror("simbhosts: lsb_init() failed");exit(-1);}hInfo = lsb_hostinfo(&hostname, &numHosts);/* get host info */if (hInfo == NULL) {lsb_perror("simbhosts: lsb_hostinfo() failed");exit (-1);}/* display the host information (name,status, job limit,num of RUN/SSUSP/USUSP jobs)*/printf("HOST_NAME STATUS JL/U NJOBS RUNSSUSP USUSP\n");printf ("%-18.18s", hInfo->host);if (hInfo->hStatus & HOST_STAT_UNLICENSED)printf(" %-9s\n", "unlicensed");else if (hInfo->hStatus & HOST_STAT_UNAVAIL)printf(" %-9s", "unavail");else if (hInfo->hStatus & HOST_STAT_UNREACH)printf(" %-9s", "unreach");else if (hInfo->hStatus & ( HOST_STAT_BUSY | HOST_STAT_WIND | HOST_STAT_DISABLED |HOST_STAT_LOCKED |HOST_STAT_FULL |HOST_STAT_NO_LIM))printf(" %-9s", "closed");elseprintf(" %-9s", "ok");if (hInfo->userJobLimit < INFINIT_INT)printf("%4d", hInfo->userJobLimit);elseprintf("%4s", "-");printf("%7d %4d %4d %4d\n", hInfo->numJobs, hInfo-> numRUN, hInfo->numSSUSP, hInfo->numUSUSP);exit(0);} /* main */
The example output from the above program follows:
hStatus is the status of the host. It is the bitwise inclusive OR of some of the following constants defined in lsbatch.h:
If none of the above holds, hStatus is set to HOST_STAT_OK to indicate that the host is ready to accept and run jobs.
The constant INFINIT_INT defined in lsf.h is used to indicate that there is no limit set for userJobLimit.