summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/ps/ps.c6
-rw-r--r--lib/libkvm/kvm_getprocs.38
-rw-r--r--lib/libkvm/kvm_proc2.c37
-rw-r--r--sys/kern/kern_sysctl.c20
-rw-r--r--sys/sys/sysctl.h28
-rw-r--r--usr.bin/pkill/pkill.c4
-rw-r--r--usr.bin/top/machine.c6
7 files changed, 87 insertions, 22 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index e7edcc3895f..77a0e48f97f 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ps.c,v 1.52 2012/04/04 16:13:11 jsing Exp $ */
+/* $OpenBSD: ps.c,v 1.53 2012/04/12 14:59:19 pirofti Exp $ */
/* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */
/*-
@@ -339,6 +339,10 @@ main(int argc, char *argv[])
if (xflg == 0 && ((int)kinfo[i]->p_tdev == NODEV ||
(kinfo[i]->p_flag & P_CONTROLT ) == 0))
continue;
+ if (!showthreads && kinfo[i]->p_tid != -1)
+ continue;
+ if (showthreads && kinfo[i]->p_tid == -1)
+ continue;
for (vent = vhead; vent; vent = vent->next) {
(vent->var->oproc)(kinfo[i], vent);
if (vent->next != NULL)
diff --git a/lib/libkvm/kvm_getprocs.3 b/lib/libkvm/kvm_getprocs.3
index e2acf477b22..93a4a7b4381 100644
--- a/lib/libkvm/kvm_getprocs.3
+++ b/lib/libkvm/kvm_getprocs.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: kvm_getprocs.3,v 1.17 2012/01/07 05:38:12 guenther Exp $
+.\" $OpenBSD: kvm_getprocs.3,v 1.18 2012/04/12 14:59:19 pirofti Exp $
.\" $NetBSD: kvm_getprocs.3,v 1.13 2003/08/07 16:44:37 agc Exp $
.\"
.\" Copyright (c) 1992, 1993
@@ -34,7 +34,7 @@
.\"
.\" @(#)kvm_getprocs.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: January 7 2012 $
+.Dd $Mdocdate: April 12 2012 $
.Dt KVM_GETPROCS 3
.Os
.Sh NAME
@@ -114,6 +114,10 @@ and
.Fn kvm_close
will overwrite this storage.
.Pp
+.Fn kvm_getprocs
+sets the thread ID field accordingly for each thread except for the
+process (main thread) which has it set to \-1.
+.Pp
.Fn kvm_getargv
returns a null-terminated argument vector that corresponds to the
command line arguments passed to process indicated by
diff --git a/lib/libkvm/kvm_proc2.c b/lib/libkvm/kvm_proc2.c
index f4306bf691b..c78a93211f6 100644
--- a/lib/libkvm/kvm_proc2.c
+++ b/lib/libkvm/kvm_proc2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_proc2.c,v 1.10 2012/03/23 15:51:25 guenther Exp $ */
+/* $OpenBSD: kvm_proc2.c,v 1.11 2012/04/12 14:59:19 pirofti Exp $ */
/* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -282,9 +282,39 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p,
limp = NULL;
#define do_copy_str(_d, _s, _l) kvm_read(kd, (u_long)(_s), (_d), (_l)-1)
+ if ((proc.p_flag & P_THREAD) == 0) {
+ FILL_KPROC(&kp, do_copy_str, &proc, &process, &pcred,
+ &ucred, &pgrp, p, proc.p_p, &sess, vmp, limp, sap,
+ 0);
+
+ /* stuff that's too painful to generalize */
+ kp.p_pid = process_pid;
+ kp.p_ppid = parent_pid;
+ kp.p_sid = leader_pid;
+ if ((process.ps_flags & PS_CONTROLT) &&
+ sess.s_ttyp != NULL) {
+ kp.p_tdev = tty.t_dev;
+ if (tty.t_pgrp != NULL &&
+ tty.t_pgrp != process.ps_pgrp &&
+ KREAD(kd, (u_long)tty.t_pgrp, &pgrp)) {
+ _kvm_err(kd, kd->program,
+ "can't read tpgrp at &x",
+ tty.t_pgrp);
+ return (-1);
+ }
+ kp.p_tpgid = tty.t_pgrp ? pgrp.pg_id : -1;
+ kp.p_tsess = PTRTOINT64(tty.t_session);
+ } else {
+ kp.p_tpgid = -1;
+ kp.p_tdev = NODEV;
+ }
+
+ memcpy(bp, &kp, esize);
+ bp += esize;
+ ++cnt;
+ }
FILL_KPROC(&kp, do_copy_str, &proc, &process, &pcred, &ucred,
- &pgrp, p, proc.p_p, &sess, vmp, limp, sap);
-#undef do_copy_str
+ &pgrp, p, proc.p_p, &sess, vmp, limp, sap, 1);
/* stuff that's too painful to generalize into the macros */
kp.p_pid = process_pid;
@@ -309,6 +339,7 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p,
memcpy(bp, &kp, esize);
bp += esize;
++cnt;
+#undef do_copy_str
}
return (cnt);
}
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index e577f6b1e35..c6b9cf784f3 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.219 2012/04/10 15:50:52 guenther Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.220 2012/04/12 14:59:19 pirofti Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -1458,8 +1458,20 @@ again:
goto err;
}
+ if ((p->p_flag & P_THREAD) == 0) {
+ if (buflen >= elem_size && elem_count > 0) {
+ fill_kproc(p, kproc, 0);
+ error = copyout(kproc, dp, elem_size);
+ if (error)
+ goto err;
+ dp += elem_size;
+ buflen -= elem_size;
+ elem_count--;
+ }
+ needed += elem_size;
+ }
if (buflen >= elem_size && elem_count > 0) {
- fill_kproc(p, kproc);
+ fill_kproc(p, kproc, 1);
error = copyout(kproc, dp, elem_size);
if (error)
goto err;
@@ -1494,7 +1506,7 @@ err:
* Fill in a kproc structure for the specified process.
*/
void
-fill_kproc(struct proc *p, struct kinfo_proc *ki)
+fill_kproc(struct proc *p, struct kinfo_proc *ki, int isthread)
{
struct process *pr = p->p_p;
struct session *s = pr->ps_session;
@@ -1502,7 +1514,7 @@ fill_kproc(struct proc *p, struct kinfo_proc *ki)
struct timeval ut, st;
FILL_KPROC(ki, strlcpy, p, pr, p->p_cred, p->p_ucred, pr->ps_pgrp,
- p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts);
+ p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts, isthread);
/* stuff that's too painful to generalize into the macros */
ki->p_pid = pr->ps_pid;
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 598ef417e16..0dfa6bb1441 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysctl.h,v 1.123 2012/04/12 10:11:41 mikeb Exp $ */
+/* $OpenBSD: sysctl.h,v 1.124 2012/04/12 14:59:18 pirofti Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
@@ -466,7 +466,7 @@ struct kinfo_proc {
#define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x))
-#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, lim, sa) \
+#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, lim, sa, isthread) \
do { \
memset((kp), 0, sizeof(*(kp))); \
\
@@ -498,15 +498,24 @@ do { \
(kp)->p_jobc = (pg)->pg_jobc; \
\
(kp)->p_estcpu = (p)->p_estcpu; \
- (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec; \
- (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec; \
+ if (isthread) { \
+ (kp)->p_rtime_sec = (p)->p_tu.tu_runtime.tv_sec; \
+ (kp)->p_rtime_usec = (p)->p_tu.tu_runtime.tv_usec; \
+ (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET; \
+ (kp)->p_uticks = (p)->p_tu.tu_uticks; \
+ (kp)->p_sticks = (p)->p_tu.tu_sticks; \
+ (kp)->p_iticks = (p)->p_tu.tu_iticks; \
+ } else { \
+ (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec; \
+ (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec; \
+ (kp)->p_tid = -1; \
+ (kp)->p_uticks = (pr)->ps_tu.tu_uticks; \
+ (kp)->p_sticks = (pr)->ps_tu.tu_sticks; \
+ (kp)->p_iticks = (pr)->ps_tu.tu_iticks; \
+ } \
(kp)->p_cpticks = (p)->p_cpticks; \
(kp)->p_pctcpu = (p)->p_pctcpu; \
\
- (kp)->p_uticks = (p)->p_uticks; \
- (kp)->p_sticks = (p)->p_sticks; \
- (kp)->p_iticks = (p)->p_iticks; \
- \
(kp)->p_tracep = PTRTOINT64((pr)->ps_tracevp); \
(kp)->p_traceflag = (pr)->ps_traceflag; \
\
@@ -587,7 +596,6 @@ do { \
} \
\
(kp)->p_cpuid = KI_NOCPU; \
- (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET; \
(kp)->p_rtableid = (pr)->ps_rtableid; \
} while (0)
@@ -933,7 +941,7 @@ int sysctl_dopool(int *, u_int, char *, size_t *);
void fill_file2(struct kinfo_file2 *, struct file *, struct filedesc *,
int, struct vnode *, struct proc *, struct proc *);
-void fill_kproc(struct proc *, struct kinfo_proc *);
+void fill_kproc(struct proc *, struct kinfo_proc *, int);
int kern_sysctl(int *, u_int, void *, size_t *, void *, size_t,
struct proc *);
diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c
index 34681f4fc2e..8b09439992f 100644
--- a/usr.bin/pkill/pkill.c
+++ b/usr.bin/pkill/pkill.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pkill.c,v 1.25 2012/03/13 09:44:49 sthen Exp $ */
+/* $OpenBSD: pkill.c,v 1.26 2012/04/12 14:59:19 pirofti Exp $ */
/* $NetBSD: pkill.c,v 1.5 2002/10/27 11:49:34 kleink Exp $ */
/*-
@@ -257,6 +257,8 @@ main(int argc, char **argv)
if ((kp->p_flag & (P_SYSTEM | P_THREAD)) != 0 ||
kp->p_pid == mypid)
continue;
+ if (kp->p_tid != -1)
+ continue;
if (matchargs) {
if ((pargv = kvm_getargv(kd, kp, 0)) == NULL)
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index e32c32c8558..0bedc42da0f 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.c,v 1.69 2011/07/12 14:57:53 tedu Exp $ */
+/* $OpenBSD: machine.c,v 1.70 2012/04/12 14:59:19 pirofti Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
@@ -367,6 +367,10 @@ get_process_info(struct system_info *si, struct process_select *sel,
* status field. Processes with P_SYSTEM set are system
* processes---these get ignored unless show_system is set.
*/
+ if (!show_threads && pp->p_tid != -1)
+ continue;
+ if (show_threads && pp->p_tid == -1)
+ continue;
if (pp->p_stat != 0 &&
(show_system || (pp->p_flag & P_SYSTEM) == 0) &&
(show_threads || (pp->p_flag & P_THREAD) == 0)) {