📄 mom_mach.c
字号:
rm_errno = RM_ERR_BADPARAM; return NULL; } 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; prpsinfo_t *pi; 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, nomemory); 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++) { pi = &proc_info[i]; if (pi->pr_uid == 0) continue; if ((jobid = pi->pr_sid) == 0) continue; DBPRT(("%s[%d]: pid %d sid %d\n", id, njids, pi->pr_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; prpsinfo_t *pi; 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++) { pi = &proc_info[i]; DBPRT(("%s[%d]: pid: %d sid %d\n", id, num_pids, pi->pr_pid, pi->pr_sid)) if (jobid != pi->pr_sid) continue; sprintf(fmt, "%d ", pi->pr_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; prpsinfo_t *pi; 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, nomemory); rm_errno = RM_ERR_SYSTEM; return NULL; } if (getprocs() == 0) { rm_errno = RM_ERR_SYSTEM; return NULL; } for (i=0; i<nproc; i++) { pi = &proc_info[i]; if ((uid = pi->pr_uid) == 0) continue; DBPRT(("%s[%d]: pid %d uid %d\n", id, nuids, pi->pr_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;}/* * The following code provoded by Fujitsu and modified for this fuction. * * Return the number of "running" PEs * * Earl J. Dodd, FAI * 4-Oct-1997 */static char *ncpus(attrib)struct rm_attribute *attrib;{ char *id = "ncpus"; unsigned int pmem; int i, npes; int maxlistlen; size_t ppnsize; opr_peid_blk_t *peidlist; if (attrib) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } npes = 0; ppnsize = 0; /* get the PE table size */ ppnsize = syscall( SYS_sysopr, SKAIGETPPN ); if (ppnsize <= 0 ) { log_err(errno, id, "SKAIGETPPN"); rm_errno = RM_ERR_SYSTEM; return NULL; } /* alloc the receiver PE table */ peidlist = (opr_peid_blk_t *)malloc(sizeof(opr_peid_blk_t)*ppnsize); if (peidlist == NULL) { log_err(errno, id, nomemory); rm_errno = RM_ERR_SYSTEM; return NULL; } /* retrieve individual PE information */ maxlistlen = syscall( SYS_sysopr, SKAIGETPEIDL, ppnsize, peidlist ); /* ** maxlistlen should = 16 (I think; really don't know what the ** return codes are) */ for (i=0; i<ppnsize; i++) { if (peidlist[i].ppid >= 0 && peidlist[i].state > 0) npes++;#ifdef DEBUG fprintf(stderr, "peid: %d, ppid = %d\n", i, peidlist[i].ppid); fprintf(stderr, "peid: %d, peid = %d\n", i, peidlist[i].peid); fprintf(stderr, "peid: %d, pp_type = 0x%x\n", i, peidlist[i].pp_type); fprintf(stderr, "peid: %d, state = 0x%x\n", i, peidlist[i].state);#endif } free(peidlist); sprintf(ret_string, "%d", npes); return ret_string;}intget_la(rv) double *rv;{ char *id = "get_la"; long load; if (kd == -1) { log_err(-1, id, nokernel); return (rm_errno = RM_ERR_SYSTEM); } if (nl[KSYM_LOAD].n_type == 0) { log_err(-1, id, "loadaverage count not found"); return (rm_errno = RM_ERR_SYSTEM); } if (lseek(kd, nl[KSYM_LOAD].n_value, SEEK_SET) == -1) { log_err(errno, id, "lseek"); return (rm_errno = RM_ERR_SYSTEM); } if (read(kd, (char *)&load, sizeof(load)) != sizeof(load)) { log_err(errno, id, "read"); return (rm_errno = RM_ERR_SYSTEM); } *rv = (double)load/256.0; return 0;}struct anoninfo ai;intgetanon(id)char *id;{ static unsigned int lastai = 0; if (lastai == reqnum) /* already have anoninfo */ return 0; if (kd == -1) { log_err(-1, id, nokernel); rm_errno = RM_ERR_SYSTEM; return 1; } if (nl[KSYM_ANON].n_type == 0) { log_err(-1, id, "anoninfo struct not found"); rm_errno = RM_ERR_SYSTEM; return 1; } if (lseek(kd, nl[KSYM_ANON].n_value, SEEK_SET) == -1) { log_err(errno, id, "lseek"); rm_errno = RM_ERR_SYSTEM; return NULL; } if (read(kd, (char *)&ai, sizeof (struct anoninfo)) != sizeof (struct anoninfo)) { log_err(errno, id, "read"); rm_errno = RM_ERR_SYSTEM; return 1; } lastai = reqnum; return 0;}static char *totmem(attrib)struct rm_attribute *attrib;{ char *id = "totmem"; if (attrib) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } if (getanon(id)) return NULL; sprintf(ret_string, "%ukb", ctob(ai.ani_max) >> 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 (getanon(id)) return NULL; /* in KB */ sprintf(ret_string, "%ukb", ctob(ai.ani_max - ai.ani_resv) >> 10); return ret_string;}static char *physmem(attrib)struct rm_attribute *attrib;{ char *id = "physmem"; unsigned int pmem; if (attrib) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } if (kd == -1) { log_err(-1, id, nokernel); rm_errno = RM_ERR_SYSTEM; return NULL; } if (nl[KSYM_PHYS].n_type == 0) { log_err(-1, id, "physmem count not found"); rm_errno = RM_ERR_SYSTEM; return 0; } if (lseek(kd, nl[KSYM_PHYS].n_value, SEEK_SET) == -1) { log_err(errno, id, "lseek"); rm_errno = RM_ERR_SYSTEM; return NULL; } if (read(kd, (char *)&pmem, sizeof (pmem)) != sizeof (pmem)) { log_err(errno, id, "read"); rm_errno = RM_ERR_SYSTEM; return NULL; } pmem *= getpagesize(); sprintf(ret_string, "%ukb", pmem >> 10); /* in KB */ 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); /* in 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 value; int job; int found = 0; int i; time_t now, start; prpsinfo_t *pi; 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++) { pi = &proc_info[i]; if (job) { if (value != pi->pr_sid) continue; } else { if ((pid_t)value != pi->pr_pid) continue; } found = 1; start = MIN(start, pi->pr_start.tv_sec); } if (found) { sprintf(ret_string, "%ld", (long)((double)(now - start) * wallfactor));; return ret_string; } rm_errno = RM_ERR_EXIST; return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -