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

📄 mom_mach.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
		DBPRT(("%s: pid %d time=%d (%d + %d + %d + %d + %d)\n",			id, pp->p_pid, addtime,			pp->p_utime, pp->p_stime, pp->p_sctime,			pc->pc_cutime, pc->pc_cstime))		cputime += (double)addtime/(double)CLK_TCK;	}	if (found) {		sprintf(ret_string, "%.2f", cputime * cputfactor);		return ret_string;	}	rm_errno = RM_ERR_EXIST;	return NULL;}char	*cput_proc(pid)pid_t	pid;{	char		*id = "cput_pid";	int		i, nproc;	time_t		addtime;	if ((nproc = getprocs()) == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	for (i=0; i<nproc; i++) {		register struct proc    *pp = &process_table[i];		register struct	pcomm	*pc;		if (pp->p_stat==0)			continue;		if (pid != pp->p_pid)			continue;		if ((pc = pp->p_pc) == NULL)			addtime = 0;		else {			addtime = pp->p_utime + pp->p_stime + pp->p_sctime +				pc->pc_cutime + pc->pc_cstime;			DBPRT(("%s: pid %d time=%d (%d + %d + %d + %d + %d)\n",				id, pid, addtime,				pp->p_utime, pp->p_stime, pp->p_sctime,				pc->pc_cutime, pc->pc_cstime))		}		sprintf(ret_string, "%.2f", ((double)addtime/(double)CLK_TCK) * cputfactor);		return ret_string;	}	rm_errno = RM_ERR_EXIST;	return NULL;}char	*cput(attrib)struct	rm_attribute	*attrib;{	char			*id = "cput";	int			value;	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, "session") == 0)		return (cput_job((pid_t)value));	else if (strcmp(attrib->a_qualifier, "proc") == 0)		return (cput_proc((pid_t)value));	else {		rm_errno = RM_ERR_BADPARAM;		return NULL;	}}char	*mem_job(jobid)pid_t	jobid;{	char		*id = "mem_job";	int		memsize;	int		i, nproc;	int		found = 0;	if ((nproc = getprocs()) == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	memsize = 0;	for (i=0; i<nproc; i++) {		register struct proc    *pp = &process_table[i];		register struct	pcomm	*pc;		if (pp->p_stat==0)			continue;		if ((pc = pp->p_pc) == NULL)			continue;		if (jobid != pc->pc_sid)			continue;		found = 1;		memsize += pc->pc_size;		DBPRT(("%s: found pid %d size=%d total=%d\n", id, pp->p_pid,				ctob(pc->pc_size), ctob(memsize)))	}	if (found) {		sprintf(ret_string, "%ukb", ctob(memsize) >> 10); /* KB */		return ret_string;	}	rm_errno = RM_ERR_EXIST;	return NULL;}char	*mem_proc(pid)pid_t	pid;{	char		*id = "mem_proc";	int		i, nproc;	if ((nproc = getprocs()) == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	for (i=0; i<nproc; i++) {		register struct proc    *pp = &process_table[i];		register struct	pcomm	*pc;		if (pp->p_stat==0)			continue;		if (pid != pp->p_pid)			continue;		if ((pc = pp->p_pc) == NULL)			break;		sprintf(ret_string, "%ukb", ctob(pc->pc_size) >> 10); /* KB */		return ret_string;	}	rm_errno = RM_ERR_EXIST;	return NULL;}char	*mem(attrib)struct	rm_attribute	*attrib;{	char		*id = "mem";	int		value;	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, "session") == 0)		return (mem_job((pid_t)value));	else if (strcmp(attrib->a_qualifier, "proc") == 0)		return (mem_proc((pid_t)value));	else {		rm_errno = RM_ERR_BADPARAM;		return NULL;	}}char	*sessions(attrib)struct	rm_attribute	*attrib;{	char			*id = "sessions";	char			*fmt;	int			i, j, nproc, njids = 0;	pid_t			*jids, *hold;	static		int	maxjid = 300;	register	pid_t	jobid;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((nproc = getprocs()) == 0) {		rm_errno = RM_ERR_SYSTEM;		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;	}	/*	** Search for members of session	*/	for (i=0; i<nproc; i++) {		register struct proc    *pp = &process_table[i];		if (pp->p_stat==0)			continue;		if (pp->p_pc == NULL)			continue;		if (pp->p_pc->pc_suid == 0)			continue;		jobid = pp->p_pc->pc_sid;		DBPRT(("%s[%d]: pid: %d sid %d\n",		       id, njids, pp->p_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*sizeof(pid_t));				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	*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 = getprocs()) == 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 proc    *pp = &process_table[i];		if (pp->p_stat==0)			continue;		if (pp->p_pc == NULL)			continue;		if ((uid = pp->p_pc->pc_suid) == 0)			continue;		DBPRT(("%s: pid %d uid %u\n",			id, (int)pp->p_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;}char	*pids(attrib)struct	rm_attribute	*attrib;{	char		*id = "pids";	pid_t		jobid;	struct	pcomm	*pc;	int		i, nproc;	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 ((nproc = getprocs()) == 0) {		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	/*	** Search for members of session	*/	fmt = ret_string;	for (i=0; i<nproc; i++) {		register struct proc    *pp = &process_table[i];		if (pp->p_stat==0)			continue;		if ((pc = pp->p_pc) == NULL)			continue;		if (jobid != pc->pc_sid)			continue;		sprintf(fmt, " %d", pp->p_pid);		fmt += strlen(fmt);		num_pids++;	}	if (num_pids == 0) {		rm_errno = RM_ERR_EXIST;		return NULL;	}	return ret_string;}static char	*totmem(attrib)struct	rm_attribute	*attrib;{	char	*id = "totmem";	struct	statfs	fsbuf;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (statfs(procfs, &fsbuf, sizeof(struct statfs), 0) == -1) {		log_err(errno, id, "statfs");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	DBPRT(("%s: bsize=%d blocks=%d\n", id, fsbuf.f_bsize, fsbuf.f_blocks))	/* in KB */	sprintf(ret_string, "%ukb", (fsbuf.f_bsize * fsbuf.f_blocks) >> 10);	return ret_string;}static char	*availmem(attrib)struct	rm_attribute	*attrib;{	char	*id = "availmem";	struct	statfs	fsbuf;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (statfs(procfs, &fsbuf, sizeof(struct statfs), 0) == -1) {		log_err(errno, id, "statfs");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	DBPRT(("%s: bsize=%d bfree=%d\n", id, fsbuf.f_bsize, fsbuf.f_bfree))	/* in KB */	sprintf(ret_string, "%ukb", (fsbuf.f_bsize * fsbuf.f_bfree) >> 10);	return ret_string;}static char	*ncpus(attrib)struct	rm_attribute	*attrib;{	char		*id = "ncpus";	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	sprintf(ret_string, "%ld", tinfo.mc_ncpu);	return ret_string;}static char	*physmem(attrib)struct	rm_attribute	*attrib;{	char		*id = "physmem";	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	/* in KB */	sprintf(ret_string, "%lukb", (tinfo.mc_msz * sizeof(int)) >> 10);	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\n",			id, param);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (statfs(param, &fsbuf, sizeof(struct statfs), 0) == -1) {		log_err(errno, id, "statfs");		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	/* in KB */	sprintf(ret_string, "%lukb", (unsigned long)((fsbuf.f_bsize * fsbuf.f_bfree) >> 10));	return ret_string;}char	*size_file(param)char	*param;{	char		*id = "size_file";

⌨️ 快捷键说明

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