version 1.108, 2020/08/23 21:11:55 |
version 1.109, 2020/08/25 07:27:34 |
|
|
int (*compare) (const void *, const void *)) |
int (*compare) (const void *, const void *)) |
{ |
{ |
int show_idle, show_system, show_threads, show_uid, show_pid, show_cmd; |
int show_idle, show_system, show_threads, show_uid, show_pid, show_cmd; |
int show_rtable, hide_rtable, hide_uid; |
int show_rtableid, hide_rtableid, hide_uid; |
int total_procs, active_procs; |
int total_procs, active_procs; |
struct kinfo_proc **prefp, *pp; |
struct kinfo_proc **prefp, *pp; |
int what = KERN_PROC_ALL; |
int what = KERN_PROC_ALL; |
|
|
show_uid = sel->uid != (uid_t)-1; |
show_uid = sel->uid != (uid_t)-1; |
hide_uid = sel->huid != (uid_t)-1; |
hide_uid = sel->huid != (uid_t)-1; |
show_pid = sel->pid != (pid_t)-1; |
show_pid = sel->pid != (pid_t)-1; |
show_rtable = sel->rtableid != -1; |
show_rtableid = sel->rtableid != -1; |
hide_rtable = sel->hrtableid != -1; |
hide_rtableid = sel->hrtableid != -1; |
show_cmd = sel->command != NULL; |
show_cmd = sel->command != NULL; |
|
|
/* count up process states and get pointers to interesting procs */ |
/* count up process states and get pointers to interesting procs */ |
|
|
(!hide_uid || pp->p_ruid != sel->huid) && |
(!hide_uid || pp->p_ruid != sel->huid) && |
(!show_uid || pp->p_ruid == sel->uid) && |
(!show_uid || pp->p_ruid == sel->uid) && |
(!show_pid || pp->p_pid == sel->pid) && |
(!show_pid || pp->p_pid == sel->pid) && |
(!hide_rtable || pp->p_rtableid != sel->hrtableid) && |
(!hide_rtableid || pp->p_rtableid != sel->hrtableid) && |
(!show_rtable || pp->p_rtableid == sel->rtableid) && |
(!show_rtableid || pp->p_rtableid == sel->rtableid) && |
(!show_cmd || cmd_matches(pp, sel->command))) { |
(!show_cmd || cmd_matches(pp, sel->command))) { |
*prefp++ = pp; |
*prefp++ = pp; |
active_procs++; |
active_procs++; |
|
|
struct kinfo_proc *pp; |
struct kinfo_proc *pp; |
int cputime; |
int cputime; |
double pct; |
double pct; |
char buf[16]; |
char second_buf[16]; |
|
|
/* find and remember the next proc structure */ |
/* find and remember the next proc structure */ |
pp = *(hndl->next_proc++); |
pp = *(hndl->next_proc++); |
|
|
/* calculate the base for cpu percentages */ |
/* calculate the base for cpu percentages */ |
pct = (double)pp->p_pctcpu / fscale; |
pct = (double)pp->p_pctcpu / fscale; |
|
|
if (pp->p_wmesg[0]) |
|
p_wait = pp->p_wmesg; |
|
else |
|
p_wait = "-"; |
|
|
|
if (get_userid == NULL) |
if (get_userid == NULL) |
snprintf(buf, sizeof(buf), "%8d", pp->p_tid); |
snprintf(second_buf, sizeof(second_buf), "%8d", pp->p_tid); |
else |
else |
snprintf(buf, sizeof(buf), "%s", (*get_userid)(pp->p_ruid, 0)); |
strlcpy(second_buf, (*get_userid)(pp->p_ruid, 0), |
|
sizeof(second_buf)); |
|
|
|
p_wait = pp->p_wmesg[0] ? pp->p_wmesg : "-"; |
|
|
/* format this entry */ |
/* format this entry */ |
snprintf(fmt, sizeof(fmt), Proc_format, pp->p_pid, buf, |
snprintf(fmt, sizeof(fmt), Proc_format, pp->p_pid, second_buf, |
pp->p_priority - PZERO, pp->p_nice - NZERO, |
pp->p_priority - PZERO, pp->p_nice - NZERO, |
format_k(pagetok(PROCSIZE(pp))), |
format_k(pagetok(PROCSIZE(pp))), |
format_k(pagetok(pp->p_vm_rssize)), |
format_k(pagetok(pp->p_vm_rssize)), |