⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xpbs_datadump.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/**         OpenPBS (Portable Batch System) v2.3 Software License* * Copyright (c) 1999-2000 Veridian Information Solutions, Inc.* All rights reserved.* * ---------------------------------------------------------------------------* For a license to use or redistribute the OpenPBS software under conditions* other than those described below, or to purchase support for this software,* please contact Veridian Systems, PBS Products Department ("Licensor") at:* *    www.OpenPBS.org  +1 650 967-4675                  sales@OpenPBS.org*                        877 902-4PBS (US toll-free)* ---------------------------------------------------------------------------* * This license covers use of the OpenPBS v2.3 software (the "Software") at* your site or location, and, for certain users, redistribution of the* Software to other sites and locations.  Use and redistribution of* OpenPBS v2.3 in source and binary forms, with or without modification,* are permitted provided that all of the following conditions are met.* After December 31, 2001, only conditions 3-6 must be met:* * 1. Commercial and/or non-commercial use of the Software is permitted*    provided a current software registration is on file at www.OpenPBS.org.*    If use of this software contributes to a publication, product, or*    service, proper attribution must be given; see www.OpenPBS.org/credit.html* * 2. Redistribution in any form is only permitted for non-commercial,*    non-profit purposes.  There can be no charge for the Software or any*    software incorporating the Software.  Further, there can be no*    expectation of revenue generated as a consequence of redistributing*    the Software.* * 3. Any Redistribution of source code must retain the above copyright notice*    and the acknowledgment contained in paragraph 6, this list of conditions*    and the disclaimer contained in paragraph 7.* * 4. Any Redistribution in binary form must reproduce the above copyright*    notice and the acknowledgment contained in paragraph 6, this list of*    conditions and the disclaimer contained in paragraph 7 in the*    documentation and/or other materials provided with the distribution.* * 5. Redistributions in any form must be accompanied by information on how to*    obtain complete source code for the OpenPBS software and any*    modifications and/or additions to the OpenPBS software.  The source code*    must either be included in the distribution or be available for no more*    than the cost of distribution plus a nominal fee, and all modifications*    and additions to the Software must be freely redistributable by any party*    (including Licensor) without restriction.* * 6. All advertising materials mentioning features or use of the Software must*    display the following acknowledgment:* *     "This product includes software developed by NASA Ames Research Center,*     Lawrence Livermore National Laboratory, and Veridian Information *     Solutions, Inc.*     Visit www.OpenPBS.org for OpenPBS software support,*     products, and information."* * 7. DISCLAIMER OF WARRANTY* * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. ANY EXPRESS* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT* ARE EXPRESSLY DISCLAIMED.* * IN NO EVENT SHALL VERIDIAN CORPORATION, ITS AFFILIATED COMPANIES, OR THE* U.S. GOVERNMENT OR ANY OF ITS AGENCIES BE LIABLE FOR ANY DIRECT OR INDIRECT,* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.* * This license will be governed by the laws of the Commonwealth of Virginia,* without reference to its choice of law rules.*//* * * xpbs_datadump - (PBS) show stats of batch jobs, queues, or servers.  *	     - basically, this code borrows heavily from "qstat". * * Authors: *      Terry Heidelberg *      Livermore Computing * *      Bruce Kelly *      National Energy Research Supercomputer Center * *      Lawrence Livermore National Laboratory *      University of California * *	Albeaus Bayucan *	Sterling Software *	NASA Ames Research Center */#include <pbs_config.h>   /* the master config generated by configure */#include "cmds.h"#include <setjmp.h> #include <pwd.h>#include <string.h>#include <ctype.h>#include <signal.h>static char ident[] = "@(#) $RCSfile: xpbs_datadump.c,v $ $Revision: 2.1.10.4 $";static int connect;static sigjmp_buf env_alrm;static void no_hang(sig)        int sig;{        fprintf(stderr, "xpbs_datadump: alarm timed-out\n");        connect = 0;	/* connection to server  has failed */	siglongjmp(env_alrm, 1);}static char *mystrdup(str)char *str;{     char *dup;     dup = (char *)malloc( (size_t)strlen(str)*sizeof(str) );	     strcpy(dup, str);     return(dup);}void set_attrop(list, a_name, r_name, v_name, op)struct attropl **list;char *a_name;char *r_name;char *v_name;enum batch_op op;{    struct attropl *attr;    attr = (struct attropl *) malloc(sizeof(struct attropl));    if ( attr == NULL ) {        fprintf(stderr, "xpbs_datadump: out of memory\n");        exit(2);    }    if ( a_name == NULL )        attr->name = NULL;    else {        attr->name = (char *) malloc(strlen(a_name)+1);        if ( attr->name == NULL ) {            fprintf(stderr, "xpbs_datadump: out of memory\n");            exit(2);        }        strcpy(attr->name, a_name);    }    if ( r_name == NULL )        attr->resource = (char *)NULL;    else {        attr->resource = (char *) malloc(strlen(r_name)+1);        if ( attr->resource == NULL ) {            fprintf(stderr, "xpbs_datadump: out of memory\n");            exit(2);        }        strcpy(attr->resource, r_name);    }    if ( v_name == NULL )        attr->value = NULL;    else {        attr->value = (char *) malloc(strlen(v_name)+1);        if ( attr->value == NULL ) {            fprintf(stderr, "xpbs_datadump: out of memory\n");            exit(2);        }        strcpy(attr->value, v_name);    }    attr->op = op;    attr->next = *list;    *list = attr;    return;}#define OPSTRING_LEN 4#define OP_LEN 2#define OP_ENUM_LEN 6static char *opstring_vals[] = { "eq", "ne", "ge", "gt", "le", "lt" };static enum batch_op opstring_enums[] = { EQ, NE, GE, GT, LE, LT };void check_op(optarg, op, optargout)char *optarg;enum batch_op *op;char *optargout;{    char opstring[OP_LEN+1];    int i;    int cp_pos;    *op = EQ;   /* default */    cp_pos = 0;    if ( optarg[0] == '.' ) {        strncpy(opstring, &optarg[1], OP_LEN);                  opstring[OP_LEN] = '\0';        cp_pos = OPSTRING_LEN;        for ( i=0; i<OP_ENUM_LEN; i++) {            if ( strncmp(opstring, opstring_vals[i], OP_LEN) == 0 ) {                *op = opstring_enums[i];                                        break;            }        }    }    strcpy(optargout, &optarg[cp_pos]);    return;}intcheck_res_op(optarg, resource_name, op, resource_value, res_pos)char *optarg;char *resource_name;enum batch_op *op;char *resource_value;char **res_pos;{    char opstring[OPSTRING_LEN];    int i;    int hit;    char *p;    p = strchr(optarg, '.');    if ( p == NULL || *p == '\0' ) {        fprintf(stderr, "xpbs_datadump: illegal -l value\n");        fprintf(stderr, "resource_list: %s\n", optarg);        return (1);    }    else {        strncpy(resource_name, optarg, p-optarg);        resource_name[p-optarg] = '\0';        *res_pos = p + OPSTRING_LEN;    }    if ( p[0] == '.' ) {        strncpy(opstring, &p[1] , OP_LEN);                      opstring[OP_LEN] = '\0';        hit = 0;        for ( i=0; i<OP_ENUM_LEN; i++) {            if ( strncmp(opstring, opstring_vals[i], OP_LEN) == 0 ) {                *op = opstring_enums[i];                                        hit = 1;                break;            }        }        if ( ! hit ) {            fprintf(stderr, "xpbs_datadump: illegal -l value\n");            fprintf(stderr, "resource_list: %s\n", optarg);            return (1);        }    }    p = strchr(*res_pos, ',');    if ( p == NULL ) {        p = strchr(*res_pos, '\0');    }    strncpy(resource_value, *res_pos, p-(*res_pos));    resource_value[p-(*res_pos)] = '\0';    if ( strlen(resource_value) == 0 ) {        fprintf(stderr, "xpbs_datadump: illegal -l value\n");        fprintf(stderr, "resource_list: %s\n", optarg);        return (1);    }    *res_pos =  (*p == '\0') ? p : ( p += 1 ) ;    if ( **res_pos == '\0' && *(p-1) == ',' ) {        fprintf(stderr, "xpbs_datadump: illegal -l value\n");        fprintf(stderr, "resource_list: %s\n", optarg);        return (1);    }    return(0);  /* ok */}intistrue(string)char *string;{    if ( strcmp(string,"TRUE") == 0 ) return TRUE;    if ( strcmp(string,"True") == 0 ) return TRUE;    if ( strcmp(string,"true") == 0 ) return TRUE;    if ( strcmp(string,"1") == 0 ) return TRUE;    return FALSE;}voidstates(string, q, r, h, w, t, e, len)char *string;char *q, *r, *h, *w, *t, *e;int len;{    char *c, *d, *f, *s, l;    c = string;    while ( isspace(*c) && *c != '\0' ) c++;    while ( *c != '\0' ) {        s = c;        while ( *c != ':' ) c++;        *c = '\0';        d = NULL;        if ( strcmp(s,"Queued") == 0 ) d = q;        else if ( strcmp(s,"Running") == 0 ) d = r;        else if ( strcmp(s,"Held")    == 0 ) d = h;        else if ( strcmp(s,"Waiting") == 0 ) d = w;        else if ( strcmp(s,"Transit") == 0 ) d = t;        else if ( strcmp(s,"Exiting") == 0 ) d = e;        c++;        if ( d != NULL ) {            s = c;            while ( *c != ' ' && *c != '\0' ) c++;            l = *c;            *c = '\0';            if ( strlen(s) > (size_t)len ) {                f = s + len;                *f = '\0';            }            strcpy(d,s);            if ( l != '\0' ) c++;        }    }}/* * print a attribute value string, formating to break a comma if possible */void prt_attr(n, r, v)	char *n;	char *r;	char *v;{	char *c;	char *comma = ",";	int   first = 1;	int   l;	int   start;		start = strlen(n) + 7;	/* 4 spaces + ' = ' is 7 */	printf("    %s", n);	if (r) {		start += strlen(r) + 1;		printf(".%s", r);	}	printf(" = ");	c = strtok(v, comma);	while (c) {		if ((l = strlen(c)) + start < 78) {			printf("%s", c);			start += l;		} else {			if ( ! first) {				printf("\n\t");				start = 9;			}			while (*c) {				putchar(*c++);				if (++start > 78) {					start = 8;					printf("\n\t");				}			}		}		if (c = strtok((char *)0, comma)) {			first = 0;			putchar(',');		}	}}#define NAMEL   12  /* printf of jobs, queues, and servers */#define NODEL   5     #define OWNERL  8   /* printf of jobs */#define TIMEUL  8   /* printf of jobs */#define STATEL  1   /* printf of jobs */#define LOCL    12  /* printf of jobs */void display_statjob(status, prtheader, full, server_name)struct batch_status *status;int prtheader;int full;char *server_name;{    struct batch_status *p;    struct attrl *a;    int l;    char *c, *e;    char jid[PBS_MAXSEQNUM+14+1];    char name[NAMEL+1];    char owner[OWNERL+1];    char nodes[NODEL+1];    char cputimeu[TIMEUL+1];    char walltimeu[TIMEUL+1];    char state[STATEL+1];    char location[LOCL+1];    char format[80];    char format2[80];    char long_name[17];    time_t epoch;    sprintf(format, "%%-%ds %%-%ds %%-%ds %%%ds %%%ds  %%%ds %%%ds  %%s@%%s %%s %%s\n",            PBS_MAXSEQNUM+14, NAMEL, OWNERL, NODEL, TIMEUL, TIMEUL, STATEL);    sprintf(format2, "%%-%ds %%-%ds %%-%ds %%%ds %%%ds  %%%ds %%%ds  %%s\n",            PBS_MAXSEQNUM+14, NAMEL, OWNERL, NODEL, TIMEUL, TIMEUL, STATEL);    if ( ! full && prtheader ) {	printf(":"); 	printf(format2, "Job id", "Name", "User", "PEs",  "CputUse",  "WalltUse", "S",  "Queue");    }    p = status;    while ( p != NULL ) {        jid[0] = '\0';        name[0] = '\0';        owner[0] = '\0';        cputimeu[0] = '\0';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -