lsb_closejobinfo()

Call lsb_closejobinfo()after receiving all job records in the connection.

Example

Below is an example of a simplified bjobs command. This program displays all pending jobs belonging to all users.

/******************************************************

* LSBLIB -- Examples

*

* simple bjobs

* Submit command as an lsbatch job with no options set

* and retrieve the job info

* It is similar to the "bjobs" command with no options.

******************************************************/

#include <stdio.h>
#include <lsf/lsbatch.h>
#include "submit_cmd.h"
int main(int argc, char **argv)
{
    /* variables for simulating submission */
    struct submit req;            /* job specifications */
    memset(&req, 0, sizeof(req)); /* initializes req */
    struct submitReply  reply; /* results of job submission */
    int  jobId;                /* job ID of submitted job */
    /* variables for simulating bjobs command */
    int  options = PEND_JOB;    /* the status of the jobs
                                whose info is returned */
    char *user="all";         /* match jobs for all users */
    struct jobInfoEnt *job;     /* detailed job info */
    int more;                   /* number of remaining jobs
                                unread */
    /* initialize LSBLIB  and  get  the  configuration
    environment */
    if (lsb_init(argv[0]) < 0) {
        lsb_perror("simbjobs: lsb_init() failed");
        exit(-1);
    }
    /* check if input is in the right format: 
     * "./simbjobs COMMAND ARGUMENTS" */
    if (argc < 2) {
        fprintf(stderr, "Usage: simbjobs command\n");
        exit(-1);
    }
    jobId = submit_cmd(&req, &reply, argc, argv); 
        /* submit a job */
    if (jobId < 0)                      /* if job submission
                                        fails, lsb_submit
                                        returns -1 */
        switch (lsberrno) {    
        /* and sets lsberrno to indicate the error */
        case LSBE_QUEUE_USE:
        case LSBE_QUEUE_CLOSED:
            lsb_perror(reply.queue);
            exit(-1);
        default:
            lsb_perror(NULL);
            exit(-1);
}
    /* gets the total number of pending job. Exits if failure */
    if (lsb_openjobinfo(0, NULL, user, NULL, NULL, options)<0) {
        lsb_perror("lsb_openjobinfo");
        exit(-1);
    }
    /* display all pending jobs */
    printf("All pending jobs submitted by all users:\n");
    for (;;) {
        job = lsb_readjobinfo(&more);   /* get the job details */
        if (job == NULL) {
        lsb_perror("lsb_readjobinfo");
        exit(-1);
    }
        printf("%s",ctime(&job->submitTime));   
        /* submission time of job */
        printf("Job <%s> ", lsb_jobid2str(job->jobId));   
        /* job ID */
        printf("of user <%s>, ", job->user);
        /* user that submits the job */
        printf("submitted from host <%s>\n", job->fromHost);            /* name of sumbission host */
        /* continue to display if there is remaining job */
        if (!more)
        /* if there are no remaining jobs undisplayed, 
           exits */
        break;
    }
    /* when finished to display the job info, close the
    connection to the mbatchd */
    lsb_closejobinfo();
    exit(0);
}

The above program will produce output similar to the following:

All pending jobs submitted by all users:
Mon Mar 1 10:34:04 EST 1996
Job <123> of user <john>, submitted from host <orange>
Mon Mar 1 11:12:11 EST 1996
Job <126> of user <john>, submitted from host <orange>
Mon Mar 1 14:11:34 EST 1996
Job <163> of user <ken>, submitted from host <apple>
Mon Mar 1 15:00:56 EST 1996
Job <199> of user <tim>, submitted from host <pear>

Use lsb_pendreason(), to print out the reasons why the job is still pending See lsb_pendreason(3) for details.