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

📄 mom_mach.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	if (strcmp(attrib->a_qualifier, "session") == 0)		return (resi_job((pid_t)value));	else if (strcmp(attrib->a_qualifier, "proc") == 0)		return (resi_proc((pid_t)value));	else {		rm_errno = RM_ERR_BADPARAM;		return NULL;	}}char	*sessions(attrib)struct	rm_attribute	*attrib;{	char			*id = "sessions";	int			i, j;	struct pst_status	*ps;	char			*fmt;	int			njids = 0;	pid_t			*jids, *hold;	static		int	maxjid = 200;	register	pid_t	jobid;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((jids = (pid_t *)calloc(maxjid, sizeof(pid_t))) == NULL) {		log_err(errno, id, "no memory");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	if (getprocs() == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	/*	** Search for members of job	*/	for (i=0; i<nproc; i++) {		ps = &proc_status[i];		if (ps->pst_uid == 0)			continue;		if ((jobid = ps->pst_sid) == 0)			continue;		DBPRT(("%s[%d]: pid %d sid %d\n",		       id, njids, ps->pst_pid, jobid))		for (j=0; j<njids; j++) {			if (jids[j] == jobid)				break;		}		if (j == njids) {		/* not found */			if (njids == maxjid) {	/* need more space */				maxjid += 100;				hold = (pid_t *)realloc(jids, maxjid);				if (hold == NULL) {					log_err(errno, id, "realloc");					rm_errno = RM_ERR_SYSTEM;					free(jids);					return NULL;				}				jids = hold;			}			jids[njids++] = jobid;	/* add jobid to list */		}	}	fmt = ret_string;	for (j=0; j<njids; j++) {		checkret(&fmt, 100);		sprintf(fmt, " %d", (int)jids[j]);		fmt += strlen(fmt);	}	free(jids);	return ret_string;}char	*nsessions(attrib)struct	rm_attribute	*attrib;{	char	*result, *ch;	int	num = 0;	if ((result = sessions(attrib)) == NULL)		return result;	for (ch=result; *ch; ch++) {		if (*ch == ' ')		/* count blanks */			num++;	}	sprintf(ret_string, "%d", num);	return ret_string;}char	*pids(attrib)struct	rm_attribute	*attrib;{	char		        *id = "pids";	pid_t		        jobid;	int		        i, j;	struct pst_status	*ps;	char		        *fmt;	int		        num_pids;	if (attrib == NULL) {		log_err(-1, id, no_parm);		rm_errno = RM_ERR_NOPARAM;		return NULL;	}	if ((jobid = (pid_t)atoi(attrib->a_value)) == 0) {		sprintf(log_buffer, "bad param: %s", attrib->a_value);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (momgetattr(NULL)) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (strcmp(attrib->a_qualifier, "session") != 0) {		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (getprocs() == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	/*	** Search for members of session	*/	fmt = ret_string;	num_pids = 0;	for (i=0; i<nproc; i++) {		ps = &proc_status[i];		DBPRT(("%s[%d]: pid: %d sid %d\n",		       id, num_pids, ps->pst_pid, ps->pst_sid))		if (jobid != ps->pst_sid)			continue;		sprintf(fmt, "%d ", ps->pst_pid);		fmt += strlen(fmt);		num_pids++;	}	if (num_pids == 0) {		rm_errno = RM_ERR_EXIST;		return NULL;	}	return ret_string;}char	*nusers(attrib)struct	rm_attribute	*attrib;{	char			*id = "nusers";	int			i, j;	struct pst_status	*ps;	int			nuids = 0;	uid_t			*uids, *hold;	static		int	maxuid = 200;	register	uid_t	uid;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((uids = (uid_t *)calloc(maxuid, sizeof(uid_t))) == NULL) {		log_err(errno, id, "no memory");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	if (getprocs() == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	for (i=0; i<nproc; i++) {		ps = &proc_status[i];		if ((uid = ps->pst_uid) == 0)			continue;		DBPRT(("%s[%d]: pid %d uid %d\n",		       id, nuids, ps->pst_pid, uid))		for (j=0; j<nuids; j++) {			if (uids[j] == uid)				break;		}		if (j == nuids) {		/* not found */			if (nuids == maxuid) {	/* need more space */				maxuid += 100;				hold = (uid_t *)realloc(uids, maxuid);				if (hold == NULL) {					log_err(errno, id, "realloc");					rm_errno = RM_ERR_SYSTEM;					free(uids);					return NULL;				}				uids = hold;			}			uids[nuids++] = uid;	/* add uid to list */		}	}	sprintf(ret_string, "%d", nuids);	free(uids);	return ret_string;}static char	*ncpus(attrib)struct	rm_attribute	*attrib;{	char		*id = "ncpus";        struct pst_dynamic pst_d;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}        if (pstat_getdynamic(&pst_d, sizeof(struct pst_dynamic), 1, 0) == -1) {          sprintf(log_buffer, "pstat_getdynamic");          log_err(errno, id, log_buffer);        }	sprintf(ret_string, "%d", (int) pst_d.psd_proc_cnt);	return ret_string;}static char	*physmem(attrib)struct	rm_attribute	*attrib;{	char		*id = "physmem";        struct pst_static pst_s;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}        if (pstat_getstatic(&pst_s, sizeof(struct pst_static), 1, 0) == -1) {          sprintf(log_buffer, "pstat_getstatic");          log_err(errno, id, log_buffer);        }        /* physical_memory is in pages - convert to KB */	sprintf(ret_string, "%ukb", (unsigned int) (pst_s.physical_memory *                                                  pst_s.page_size / 1024));	return ret_string;}char	*size_fs(param)char	*param;{	char		*id = "size_fs";	FILE		*mf;	struct	mntent	*mp;	struct	statvfs	fsbuf;	if (param[0] != '/') {		sprintf(log_buffer, "%s: not full path filesystem name: %s\n",			id, param);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (statvfs(param, &fsbuf) == -1) {		log_err(errno, id, "statvfs");		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	/* in KB */	sprintf(ret_string, "%lukb", (unsigned long)(((double)fsbuf.f_bsize * (double)fsbuf.f_bfree) / 1024.0));	return ret_string;}char	*size_file(param)char	*param;{	char		*id = "size_file";	struct	stat	sbuf;	if (param[0] != '/') {		sprintf(log_buffer, "%s: not full path filesystem name: %s\n",			id, param);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (stat(param, &sbuf) == -1) {		log_err(errno, id, "stat");		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	sprintf(ret_string, "%ukb", sbuf.st_size >> 10); /* KB */	return ret_string;}char	*size(attrib)struct	rm_attribute	*attrib;{	char	*id = "size";	char	*param;	if (attrib == NULL) {		log_err(-1, id, no_parm);		rm_errno = RM_ERR_NOPARAM;		return NULL;	}	if (momgetattr(NULL)) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	param = attrib->a_value;	if (strcmp(attrib->a_qualifier, "file") == 0)		return (size_file(param));	else if (strcmp(attrib->a_qualifier, "fs") == 0)		return (size_fs(param));	else {		rm_errno = RM_ERR_BADPARAM;		return NULL;	}}time_t	maxtm;voidsetmax(dev)char	*dev;{	struct	stat	sb;	if (stat(dev, &sb) == -1)		return;	if (maxtm < sb.st_atime)		maxtm = sb.st_atime;	return;}char	*idletime(attrib)struct	rm_attribute	*attrib;{	char	*id = "idletime";	DIR	*dp;	struct	dirent	*de;	char	ttyname[50];	time_t	curtm;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((dp=opendir("/dev/pts")) == NULL) {		log_err(errno, id, "opendir /dev");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	maxtm = 0;	curtm = time(NULL);	setmax("/dev/mouse");	while ((de=readdir(dp)) != NULL) {		char	*name = de->d_name;		if (maxtm >= curtm)			break;		if (*name == '.')			continue;		sprintf(ttyname, "/dev/pts/%s", name);		setmax(ttyname);	}	closedir(dp);	sprintf(ret_string, "%d", MAX(0, curtm - maxtm));	return ret_string;}static char	*walltime(attrib)struct	rm_attribute	*attrib;{	char			*id = "walltime";	int			i;	int			value, job, found = 0;	time_t			now, start;	struct pst_status	*ps;	if (attrib == NULL) {		log_err(-1, id, no_parm);		rm_errno = RM_ERR_NOPARAM;		return NULL;	}	if ((value = atoi(attrib->a_value)) == 0) {		sprintf(log_buffer, "bad param: %s", attrib->a_value);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (momgetattr(NULL)) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (strcmp(attrib->a_qualifier, "proc") == 0)		job = 0;	else if (strcmp(attrib->a_qualifier, "session") == 0)		job = 1;	else {		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((now = time(NULL)) <= 0) {		log_err(errno, id, "time");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	if (getprocs() == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	start = now;	for (i=0; i<nproc; i++) {		ps = &proc_status[i];		if (job) {			if (value != ps->pst_sid)				continue;		}		else {			if ((pid_t)value != ps->pst_pid)				continue;		}		found = 1;		start = MIN(start, ps->pst_start);	}	if (found) {		sprintf(ret_string, "%ld", (long)((double)(now - start) * wallfactor));		return ret_string;	}	rm_errno = RM_ERR_EXIST;	return NULL;}intget_la(rv)	double 	*rv;{	char	*id = "get_la";        struct pst_dynamic pst_d;        if (pstat_getdynamic(&pst_d, sizeof(struct pst_dynamic), 1, 0) == -1) {          sprintf(log_buffer, "pstat_getdynamic");          log_err(errno, id, log_buffer);	  return (rm_errno = RM_ERR_SYSTEM);        }	*rv = (double)pst_d.psd_avg_1_min;	return 0;}static char *cpuspeed(attrib)struct	rm_attribute	*attrib;{  char	*id = "cpuspeed";  double scale;  double freq;  if (attrib) {    log_err(-1, id, extra_parm);    rm_errno = RM_ERR_BADPARAM;    return NULL;  }  /* don't know how to get on hpux - fake it */  freq = 100*1000*1000;  /*   * Scale is the 1 over the clock frequency, in Mhz   */  scale = ((double) freq / (1000 * 1000));  sprintf(ret_string, "%d", (int) scale);  return ret_string;}static char *cputype(attrib)struct	rm_attribute	*attrib;{  char	*id = "cputype";  static long cputype = -1;  static char *cputypename;  if (attrib) {    log_err(-1, id, extra_parm);    rm_errno = RM_ERR_BADPARAM;    return NULL;  }  if ( cputype == -1 ) {    cputype = sysconf(_SC_CPU_VERSION);    if (cputype < 0) {        sprintf(cputypename, "[errno = %d]", errno);    } else {      switch (cputype) {        case CPU_HP_MC68020: cputypename = "Motorola MC68020";                             break;        case CPU_HP_MC68030: cputypename = "Motorola MC68030";                             break;        case CPU_HP_MC68040: cputypename = "Motorola MC68040";                             break;        case CPU_PA_RISC1_0: cputypename = "HP PA-RISC1.0";                             break;        case CPU_PA_RISC1_1: cputypename = "HP PA-RISC1.1";                             break;        case CPU_PA_RISC1_2: cputypename = "HP PA-RISC1.2";                             break;        case CPU_PA_RISC2_0: cputypename = "HP PA-RISC2.0";                             break;        default:             cputypename = "unknown";      }    }  }  return cputypename;}static char *platform(attrib)struct	rm_attribute	*attrib;{  char	*id = "platform";  struct utsname name;  if (attrib) {    log_err(-1, id, extra_parm);    rm_errno = RM_ERR_BADPARAM;    return NULL;  }  uname(&name);  sprintf (ret_string, "%s %s %s", name.sysname, name.release, name.machine);  return ret_string;}static char *valid_user(attrib)struct	rm_attribute	*attrib;{  char	*id = "valid_user";  struct passwd *p;  if (attrib == NULL || attrib -> a_value == NULL ) {    log_err(-1, id, no_parm);    rm_errno = RM_ERR_NOPARAM;    return NULL;  }  p = getpwnam(attrib -> a_value);  if ( p ) {    return "yes";  } else {    return "no";  }}

⌨️ 快捷键说明

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