summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-02-08 12:31:02 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-02-08 12:31:02 +0000
commit505b071a12a5c2703cf1667e2ede0f44439bfe8f (patch)
tree80d20c9b36aad2e89218335be1f14f3607669180
parentdd962b60d0b6e8f81a5a5b396539d6aa8cd40f0c (diff)
More tweakery.
-rw-r--r--osdep-freebsd.c22
-rw-r--r--osdep-openbsd.c39
2 files changed, 54 insertions, 7 deletions
diff --git a/osdep-freebsd.c b/osdep-freebsd.c
index ef456422..8170a6c2 100644
--- a/osdep-freebsd.c
+++ b/osdep-freebsd.c
@@ -1,4 +1,4 @@
-/* $Id: osdep-freebsd.c,v 1.8 2009-02-07 19:33:07 nicm Exp $ */
+/* $Id: osdep-freebsd.c,v 1.9 2009-02-08 12:31:02 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -85,13 +85,31 @@ retry:
if (is_runnable(p) && !is_runnable(bestp))
bestp = p;
+ else if (!is_runnable(p) && is_runnable(bestp))
+ continue;
+
if (!is_stopped(p) && is_stopped(bestp))
bestp = p;
+ else if (is_stopped(p) && !is_stopped(bestp))
+ continue;
+
if (p->ki_estcpu > bestp->ki_estcpu)
bestp = p;
+ else if (p->ki_estcpu < bestp->ki_estcpu)
+ continue;
+
if (p->ki_slptime < bestp->ki_slptime)
bestp = p;
- /* XXX children? */
+ else if (p->ki_slptime > bestp->ki_slptime)
+ continue;
+
+ if (strcmp(p->ki_comm, p->ki_comm) < 0)
+ bestp = p;
+ else if (strcmp(p->ki_comm, p->ki_comm) > 0)
+ continue;
+
+ if (p->ki_pid > bestp->ki_pid)
+ bestp = p;
}
if (bestp != NULL) {
procname = get_proc_argv0(bestp->ki_pid);
diff --git a/osdep-openbsd.c b/osdep-openbsd.c
index 0dc3e3e1..e7dcdd08 100644
--- a/osdep-openbsd.c
+++ b/osdep-openbsd.c
@@ -1,4 +1,4 @@
-/* $Id: osdep-openbsd.c,v 1.10 2009-02-07 19:41:35 nicm Exp $ */
+/* $Id: osdep-openbsd.c,v 1.11 2009-02-08 12:31:02 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,9 +39,9 @@ char *get_argv0(int, char *);
char *get_proc_argv0(pid_t);
char *
-get_argv0(__attribute__ ((unused)) int fd, char *tty)
+get_argv0(int fd, char *tty)
{
- int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_TTY, 0 };
+ int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, 0 };
struct stat sb;
size_t len;
struct kinfo_proc *buf, *newbuf;
@@ -53,7 +53,8 @@ get_argv0(__attribute__ ((unused)) int fd, char *tty)
if (stat(tty, &sb) == -1)
return (NULL);
- mib[3] = sb.st_rdev;
+ if ((mib[3] = tcgetpgrp(fd)) == -1)
+ return (NULL);
retry:
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) == -1)
@@ -78,22 +79,50 @@ retry:
if (buf[i].kp_eproc.e_tdev != sb.st_rdev)
continue;
p = &buf[i].kp_proc;
- if (bestp == NULL)
+ if (bestp == NULL) {
bestp = p;
+ continue;
+ }
if (is_runnable(p) && !is_runnable(bestp))
bestp = p;
+ else if (!is_runnable(p) && is_runnable(bestp))
+ continue;
+
if (!is_stopped(p) && is_stopped(bestp))
bestp = p;
+ else if (is_stopped(p) && !is_stopped(bestp))
+ continue;
+
if (p->p_estcpu > bestp->p_estcpu)
bestp = p;
+ else if (p->p_estcpu < bestp->p_estcpu)
+ continue;
+
if (p->p_slptime < bestp->p_slptime)
bestp = p;
+ else if (p->p_slptime > bestp->p_slptime)
+ continue;
+
if (p->p_flag & P_SINTR && !(bestp->p_flag & P_SINTR))
bestp = p;
+ else if (!(p->p_flag & P_SINTR) && bestp->p_flag & P_SINTR)
+ continue;
+
if (LIST_FIRST(&p->p_children) == NULL &&
LIST_FIRST(&bestp->p_children) != NULL) /* XXX ugh */
bestp = p;
+ else if (LIST_FIRST(&p->p_children) != NULL &&
+ LIST_FIRST(&bestp->p_children) == NULL)
+ continue;
+
+ if (strcmp(p->p_comm, p->p_comm) < 0)
+ bestp = p;
+ else if (strcmp(p->p_comm, p->p_comm) > 0)
+ continue;
+
+ if (p->p_pid > bestp->p_pid)
+ bestp = p;
}
if (bestp != NULL) {
procname = get_proc_argv0(bestp->p_pid);