DragonFly submit List (threaded) for 2007-08
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]
[PATCH] add options to ps(1) to display lwp data
Hello,
While debugging http://bugs.dragonflybsd.org/issue761, I couldn't find
a way to display lwps.
Here is a patch to fix that inspired from FreeBSD.
Cheers,
Nicolas
----------------
Add '-H', 'nlwp', and 'lwp' options to ps(1) to display some LWP data (same
options as FreeBSD). See man changes for details.
Fix bug in sysctl(KERN_PROC, ...): only one lwp was returned whether or not
KERN_PROC_FLAG_LWP specified.
Index: dfly/src/bin/ps/keyword.c
===================================================================
--- dfly.orig/src/bin/ps/keyword.c 2007-02-24 05:36:10.000000000 +0100
+++ dfly/src/bin/ps/keyword.c 2007-08-12 16:29:19.000000000 +0200
@@ -115,6 +115,8 @@
NULL},
{"logname", "", "login", 0, NULL, NULL, 0, 0, 0, NULL, NULL},
{"lstart", "STARTED", NULL, LJUST|USER, lstarted, NULL, 28, 0, 0, NULL, NULL},
+ {"lwp", "LWP", NULL, 0, lpvar, NULL, PIDLEN, LPOFF(tid), UINT, PIDFMT,
+ NULL},
{"majflt", "MAJFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_majflt), LONG, "ld",
NULL},
{"minflt", "MINFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_minflt), LONG, "ld",
@@ -127,6 +129,8 @@
{"nice", "NI", NULL, 0, pnice, NULL, 3, 0, 0, NULL, NULL},
{"nivcsw", "NIVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nivcsw), LONG, "ld",
NULL},
+ {"nlwp", "NLWP", NULL, 0, pvar, NULL, 4, POFF(nthreads), INT, "d",
+ NULL},
{"nsignals", "", "nsigs", 0, NULL, NULL, 0, 0, 0, NULL, NULL},
{"nsigs", "NSIGS", NULL, USER, rvar, NULL, 4, ROFF(ru_nsignals), LONG, "ld",
NULL},
Index: dfly/src/bin/ps/ps.c
===================================================================
--- dfly.orig/src/bin/ps/ps.c 2007-02-01 11:33:25.000000000 +0100
+++ dfly/src/bin/ps/ps.c 2007-08-12 14:34:47.000000000 +0200
@@ -79,10 +79,10 @@
static int needuser, needcomm, needenv;
#if defined(LAZY_PS)
static int forceuread=0;
-#define PS_ARGS "aCcefghjLlM:mN:O:o:p:rSTt:U:uvwx"
+#define PS_ARGS "aCcefgHhjLlM:mN:O:o:p:rSTt:U:uvwx"
#else
static int forceuread=1;
-#define PS_ARGS "aCceghjLlM:mN:O:o:p:rSTt:U:uvwx"
+#define PS_ARGS "aCcegHhjLlM:mN:O:o:p:rSTt:U:uvwx"
#endif
enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT;
@@ -120,7 +120,7 @@
pid_t pid;
uid_t *uids;
int all, ch, flag, i, fmt, lineno, nentries, nocludge, dropgid;
- int prtheader, wflag, what, xflg, uid, nuids;
+ int prtheader, wflag, what, xflg, uid, nuids, showlwps;
char errbuf[_POSIX2_LINE_MAX];
const char *cp, *nlistf, *memf;
size_t btime_size = sizeof(struct timeval);
@@ -156,7 +156,7 @@
argv[1] = kludge_oldps_options(argv[1]);
}
- all = fmt = prtheader = wflag = xflg = 0;
+ all = fmt = prtheader = wflag = xflg = showlwps = 0;
pid = -1;
nuids = 0;
uids = NULL;
@@ -179,6 +179,9 @@
break;
case 'g':
break; /* no-op */
+ case 'H':
+ showlwps = KERN_PROC_FLAG_LWP;
+ break;
case 'h':
prtheader = ws.ws_row > 5 ? ws.ws_row : 22;
break;
@@ -359,6 +362,8 @@
what = KERN_PROC_ALL;
flag = 0;
}
+ what |= showlwps;
+
/*
* select procs
*/
Index: dfly/src/sys/kern/kern_proc.c
===================================================================
--- dfly.orig/src/sys/kern/kern_proc.c 2007-02-19 02:14:23.000000000 +0100
+++ dfly/src/sys/kern/kern_proc.c 2007-08-12 15:41:00.000000000 +0200
@@ -651,8 +651,8 @@
int error;
fill_kinfo_proc(p, &ki);
- if ((flags & KERN_PROC_FLAG_LWP) == 0)
- skp = 1;
+ if ((flags & KERN_PROC_FLAGMASK) == KERN_PROC_FLAG_LWP)
+ skp = 0;
FOREACH_LWP_IN_PROC(lp, p) {
fill_kinfo_lwp(lp, &ki.kp_lwp);
output:
Index: dfly/src/bin/ps/ps.1
===================================================================
--- dfly.orig/src/bin/ps/ps.1 2007-08-12 16:01:59.000000000 +0200
+++ dfly/src/bin/ps/ps.1 2007-08-12 16:34:34.000000000 +0200
@@ -41,7 +41,7 @@
.Nd process status
.Sh SYNOPSIS
.Nm
-.Op Fl aCcefhjlmrSTuvwx
+.Op Fl aCcefHhjlmrSTuvwx
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl O Ar fmt
@@ -94,6 +94,8 @@
.It Fl f
Show commandline and environment information about swapped out processes.
This option is honored only if the uid of the user is 0.
+.It Fl H
+Show all lightweight processes (LWP) associated with each process.
.It Fl h
Repeat the information header as often as necessary to guarantee one
header per page of information.
@@ -369,6 +371,8 @@
.Cm logname )
.It Cm lstart
time started
+.It Cm lwp
+lightweight process ID
.It Cm majflt
total page faults
.It Cm minflt
@@ -382,6 +386,8 @@
.Cm ni )
.It Cm nivcsw
total involuntary context switches
+.It Cm nlwp
+number of lightweight processes
.It Cm nsigs
total signals taken (alias
.Cm nsignals )
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]