📄 mom_mach.c
字号:
/* * Restart the job from the checkpoint file. * * Return -1 on error or sid if okay. */long mach_restart(ptask, file) task *ptask; char *file;{ return (-1);}/*** Return 1 if proc table can be read, 0 otherwise.*/intgetprocs(){ static unsigned int lastproc = 0; char *id = "getprocs"; caddr_t *kernel_proc; int i, len; if (lastproc == reqnum) /* don't need new proc table */ return 1; if (mom_get_sample() != PBSE_NONE) return 0; lastproc = reqnum; return 1;}char *cput_job(jobid)pid_t jobid;{ char *id = "cput_job"; double ses_time; int i; unsigned long cputime; if (getprocs() == 0) { rm_errno = RM_ERR_SYSTEM; return NULL; } cputime = 0; for (i=0; i<nproc; i++) { struct kinfo_proc *pp = &proc_tbl[i]; if (jobid != sess_tbl[i]) continue; cputime += tv(pp->kp_proc.p_rtime); if (pp->kp_proc.p_ru == NULL) { struct pstats ps; if (pp->kp_proc.p_stats == NULL) continue; if (kvm_read(kd, (u_long)pp->kp_proc.p_stats, &ps, sizeof(ps)) != sizeof(ps)) { log_err(errno, id, "kvm_read(pstats)"); continue; } cputime += tv(ps.p_ru.ru_utime) + tv(ps.p_ru.ru_stime) + tv(ps.p_cru.ru_utime) + tv(ps.p_cru.ru_stime); } else { struct rusage ru; if (kvm_read(kd, (u_long)pp->kp_proc.p_ru, &ru, sizeof(ru)) != sizeof(ru)) { log_err(errno, id, "kvm_read(session)"); continue; } cputime += tv(ru.ru_utime) + tv(ru.ru_stime); } DBPRT(("%s: ses %d pid %d cputime %d\n", id, jobid, pp->kp_proc.p_pid, cputime)) } sprintf(ret_string, "%.2f", (double)cputime * cputfactor); return ret_string;}char *cput_proc(pid)pid_t pid;{ char *id = "cput_proc"; struct pstats ps; uint i, cputime; for (i=0; i<nproc; i++) { struct kinfo_proc *pp = &proc_tbl[i]; if (pid != pp->kp_proc.p_pid) continue; cputime = tv(pp->kp_proc.p_rtime); if (pp->kp_proc.p_ru == NULL) { struct pstats ps; if (pp->kp_proc.p_stats == NULL) break; if (kvm_read(kd, (u_long)pp->kp_proc.p_stats, &ps, sizeof(ps)) != sizeof(ps)) { log_err(errno, id, "kvm_read(pstats)"); break; } cputime += tv(ps.p_ru.ru_utime) + tv(ps.p_ru.ru_stime) + tv(ps.p_cru.ru_utime) + tv(ps.p_cru.ru_stime); } else { struct rusage ru; if (kvm_read(kd, (u_long)pp->kp_proc.p_ru, &ru, sizeof(ru)) != sizeof(ru)) { log_err(errno, id, "kvm_read(session)"); break; } cputime += tv(ru.ru_utime) + tv(ru.ru_stime); } DBPRT(("%s: pid %d cputime %d\n", id, pid, cputime)) sprintf(ret_string, "%.2f", (double)cputime * 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 i; int memsize, addmem; int found = 0; if (getprocs() == 0) { rm_errno = RM_ERR_SYSTEM; return NULL; } memsize = 0; for (i=0; i<nproc; i++) { struct kinfo_proc *pp = &proc_tbl[i]; if (jobid != sess_tbl[i]) continue; found = 1; addmem = pp->kp_eproc.e_vm.vm_tsize + pp->kp_eproc.e_vm.vm_dsize + pp->kp_eproc.e_vm.vm_ssize; memsize += addmem; } if (found) { sprintf(ret_string, "%ukb", ctob(memsize) >> 10); /* in KB */ return ret_string; } rm_errno = RM_ERR_EXIST; return NULL;}char *mem_proc(pid)pid_t pid;{ char *id = "mem_proc"; int i, memsize; if (getprocs() == 0) { rm_errno = RM_ERR_SYSTEM; return NULL; } for (i=0; i<nproc; i++) { struct kinfo_proc *pp = &proc_tbl[i]; if (pid != pp->kp_proc.p_pid) continue; memsize = pp->kp_eproc.e_vm.vm_tsize + pp->kp_eproc.e_vm.vm_dsize + pp->kp_eproc.e_vm.vm_ssize; sprintf(ret_string, "%ukb", ctob(memsize) >> 10); /* in 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; }}static char *resi_job(jobid)pid_t jobid;{ char *id = "resi_job"; int i, found; int resisize; if (getprocs() == 0) { rm_errno = RM_ERR_SYSTEM; return NULL; } resisize = 0; found = 0; for (i=0; i<nproc; i++) { struct kinfo_proc *pp = &proc_tbl[i]; if (jobid != sess_tbl[i]) continue; found = 1; resisize += pp->kp_eproc.e_vm.vm_rssize; } if (found) { sprintf(ret_string, "%ukb", ctob(resisize) >> 10); /* in kb */ return ret_string; } rm_errno = RM_ERR_EXIST; return NULL;}static char *resi_proc(pid)pid_t pid;{ char *id = "resi_proc"; int i; int resisize; if (getprocs() == 0) { rm_errno = RM_ERR_SYSTEM; return NULL; } resisize = 0; for (i=0; i<nproc; i++) { struct kinfo_proc *pp = &proc_tbl[i]; if (pid != pp->kp_proc.p_pid) continue; resisize = pp->kp_eproc.e_vm.vm_rssize; sprintf(ret_string, "%ukbd", ctob(resisize) >> 10); /* in KB */ return ret_string; } rm_errno = RM_ERR_EXIST; return NULL;}static char *resi(attrib)struct rm_attribute *attrib;{ char *id = "resi"; 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 (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; char *fmt; int njids = 0; pid_t *jids, jobid; if (attrib) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } if (getprocs() == 0) { rm_errno = RM_ERR_SYSTEM; return NULL; } if ((jids = (pid_t *)calloc(nproc, sizeof(pid_t))) == NULL) { log_err(errno, id, "no memory"); rm_errno = RM_ERR_SYSTEM; return NULL; } /* ** Search for job */ for (i=0; i<nproc; i++) { struct kinfo_proc *pp = &proc_tbl[i]; if (pp->kp_eproc.e_pcred.p_ruid == 0) continue; jobid = sess_tbl[i]; DBPRT(("%s: pid %d sid %u\n", id, (int)pp->kp_proc.p_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", (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; 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 (getprocs() == 0) { rm_errno = RM_ERR_SYSTEM; return NULL; } /* ** Search for members of session */ fmt = ret_string; for (i=0; i<nproc; i++) { struct kinfo_proc *pp = &proc_tbl[i]; DBPRT(("%s[%d]: pid %d sid %u\n", id, num_pids, pp->kp_proc.p_pid, sess_tbl[i])) if (jobid != sess_tbl[i]) continue; checkret(&fmt, 100); sprintf(fmt, " %d", pp->kp_proc.p_pid); fmt += strlen(fmt); num_pids++; } if (num_pids == 0) { rm_errno = RM_ERR_EXIST; return NULL; } return ret_string;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -