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

📄 mom_mach.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((nproc = getproctab()) == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	if ((jids = calloc(nproc, sizeof(pid_t))) == NULL) {		log_err(errno, id, "no memory");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	/*	** Search for session	*/	for (i=0; i<nproc; i++) {		register struct procsinfo	*pp = &proc_tbl[i];		if (pp->pi_state == SNONE)			continue;		if (pp->pi_suid == 0)			continue;		jobid = pp->pi_sid;		if (jobid == 0)			continue;		DBPRT(("%s: pid %d sid %u\n", id, pp->pi_pid, jobid))		for (j=0; j<njids; j++) {			if (jids[j] == jobid)				break;		}		if (j == njids)			/* not found */			jids[njids++] = jobid;	/* so add it to list */	}	fmt = ret_string;	for (j=0; j<njids; j++) {		checkret(&fmt, 100);		sprintf(fmt, " %d", 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			nproc;	int			i;	char			*fmt;	int			num_pids = 0;	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 ((nproc = getproctab()) == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	/*	** Search for members of session	*/	fmt = ret_string;	for (i=0; i<nproc; i++) {		register struct procsinfo	*pp = &proc_tbl[i];		if (pp->pi_state == SNONE)			continue;		if (jobid != pp->pi_sid)			continue;		checkret(&fmt, 100);		sprintf(fmt, " %d", pp->pi_pid);		fmt += strlen(fmt);		num_pids++;		DBPRT(("%s[%d]: pid %d sid %u\n",		       id, num_pids, pp->pi_pid, pp->pi_sid))	}	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			nproc;	int			i, j;	int			nuids = 0;	uid_t			*uids, uid;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((nproc = getproctab()) == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	if ((uids = calloc(nproc, sizeof(uid_t))) == NULL) {		log_err(errno, id, "no memory");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	for (i=0; i<nproc; i++) {		register struct procsinfo	*pp = &proc_tbl[i];		if (pp->pi_state == SNONE)			continue;		if ((uid = pp->pi_suid) == 0)			continue;		DBPRT(("%s: pid %d uid %u\n", id, pp->pi_pid, uid))		for (j=0; j<nuids; j++) {			if (uids[j] == uid)				break;		}		if (j == nuids)			/* not found */			uids[nuids++] = uid;	/* so add it to list */	}	sprintf(ret_string, "%d", nuids);	free(uids);	return ret_string;}uint	swap_free;uint	swap_size;intgetswap(id)char	*id;{	static	unsigned	int	lastai = 0;	int	i;	struct	pginfo	pginfo;	if (lastai == reqnum)	/* already have anoninfo */		return 0;	swap_free = swap_size = 0;	for (i=0; swap_dev[i]; i++) {		if (swapqry(swap_dev[i], &pginfo) == -1) {			log_err(errno, id, swap_dev[i]);			continue;		}		swap_free += pginfo.free;		swap_size += pginfo.size;	}	lastai = reqnum;	return 0;}static char	*totmem(attrib)struct	rm_attribute	*attrib;{	char	*id = "totmem";	ulong	tmem;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (getswap(id))		return NULL;	sprintf(ret_string, "%lukb", (swap_size * page_size) >> 10); /* KB */	return ret_string;}static char	*availmem(attrib)struct	rm_attribute	*attrib;{	char	*id = "availmem";	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (getswap(id))		return NULL;	sprintf(ret_string, "%lukb", (swap_free * page_size) >> 10); /* KB */	return ret_string;}char	*size_fs(param)char	*param;{	char		*id = "size_fs";	FILE		*mf;	struct	mntent	*mp;	struct	statfs	fsbuf;	if (param[0] != '/') {		sprintf(log_buffer, "%s: not full path filesystem name: %s",			id, param);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (statfs(param, &fsbuf) == -1) {		log_err(errno, id, "statfs");		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	/* in KB */	sprintf(ret_string, "%lukb", (unsigned long)(((double)fsbuf.f_bsize * (double)fsbuf.f_bavail) / 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",			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) {		DBPRT(("%s: prev %d curr %d\n", dev, maxtm, sb.st_atime))		maxtm = sb.st_atime;	}	return;}intinteresting(name)    char	*name;{	static	char	*list[] = {		"kbd",		"mouse",		"pty",		"tty",		NULL	};	char	**el;	if (name == NULL || *name == '.')		return 0;	for (el=list; *el; el++) {		if (strncmp(name, *el, strlen(*el)) == 0)			return 1;	}	return 0;}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")) == NULL) {		log_err(errno, id, "opendir /dev");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	maxtm = 0;	curtm = time(NULL);	while ((de=readdir(dp)) != NULL) {		if (maxtm >= curtm)			break;		if (!interesting(de->d_name))			continue;		sprintf(ttyname, "/dev/%s", de->d_name);		setmax(ttyname);	}	closedir(dp);	if ((maxtm < curtm) &&	    ((dp=opendir("/dev/pts")) != NULL)) {		while ((de=readdir(dp)) != NULL) {			if (maxtm >= curtm)				break;			if (de->d_name[0] == '.')				continue;			sprintf(ttyname, "/dev/pts/%s", de->d_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";	pid_t			value;	int			i, nproc, job, found = 0;	time_t			now, start;	if (attrib == NULL) {		log_err(-1, id, no_parm);		rm_errno = RM_ERR_NOPARAM;		return NULL;	}	if ((value = (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, "proc") == 0)		job = 0;	else if (strcmp(attrib->a_qualifier, "session") == 0)		job = 1;	else {		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((nproc = getproctab()) == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	if ((now = time(NULL)) <= 0) {		log_err(errno, id, "time");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	start = now;	for (i=0; i<nproc; i++) {		struct	procsinfo	*pp = &proc_tbl[i];		if (pp->pi_state == SNONE)			continue;		if (job) {			if (value != pp->pi_sid)				continue;		}		else {			if (value != pp->pi_pid)				continue;		}		found = 1;		DBPRT(("%s: pid %d start %d\n", id, pp->pi_pid, pp->pi_start))		start = MIN(start, pp->pi_start);	}	if (found) {		sprintf(ret_string, "%ld", (long)((double)(now - start) * wallfactor));		return ret_string;	}	rm_errno = RM_ERR_EXIST;	return NULL;}static char *physmem(attrib)struct  rm_attribute    *attrib;{	if (attrib) {		log_err(-1, "physmem", extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	sprintf(ret_string, "%lukb", realmem);	return (ret_string);}#define	FSCALE	(1<<16)intget_la(rv)	double	*rv;{	char	*id = "get_la";	long	load;	if (kd == NULL) {		log_err(-1, id, nokernel);		return (rm_errno = RM_ERR_SYSTEM);	}	if (kvm_read(kd, nl[KSYM_LOAD].n_value, (char *)&load,		     sizeof(load)) != sizeof(load)) {		log_err(errno, id, "kvm_read");		return (rm_errno = RM_ERR_SYSTEM);	}	*rv = (double)load/FSCALE;	return 0;}#if IBM_SP2==1/* * dummy synbol for unknown IBM job manager routine, * wish IBM would give out some information about it... */void ppslog(){}/***	Check that node_name matches one of the names in node_list**	separated by '+'s.  The match is only done up to the first**	'.' character.**	Return 1 for a match and 0 for no match.*/intmatch(node_name, node_list)    char	*node_name;    char	*node_list;{	char		*cp, *name;	/*	** start a loop through "node_list"	** making one pass only	*/	name = node_name;	cp = node_list;	while (*cp) {		/*		** step through both name and		** nodes matching each char		*/		for (; *name; name++, cp++) {			if (*name != *cp)				break;		}		/*		** once we are done with the		** test loop above, check		** to see if a match is found		** by having gotten to the		** end of name and the end		** of one node name in "node_list"		*/		if ((*name == '\0' || *name == '.') &&		    (*cp == '+' || *cp == '\0' || *cp == '.'))			return 1;		/*		** if we get here, there was no match		** skip the rest of the node name		** (and plus sign) and reset name to		** the one we are looking for		*/		while (*cp != '+' && *cp != '\0')			cp++;		if (*cp == '+')			cp++;		name = node_name;	}	return 0;}#endif /* IBM_SP2 */

⌨️ 快捷键说明

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