summaryrefslogtreecommitdiffstats
path: root/bin/ps
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
committerobrien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
commit3028e3f8aba938dfd0bf9fda987b8a72140b8027 (patch)
treeb2f038222ff8a70f687652441df00d2b564c8abe /bin/ps
parent952a6d5a7cd3d3f9007acfa06805262fc04a105f (diff)
parent1d08d5f677c1dfa810e381073590adbae19cc69f (diff)
downloadFreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.zip
FreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.tar.gz
Sync with HEAD.
Diffstat (limited to 'bin/ps')
-rw-r--r--bin/ps/extern.h2
-rw-r--r--bin/ps/fmt.c13
-rw-r--r--bin/ps/ps.13
-rw-r--r--bin/ps/ps.c31
4 files changed, 35 insertions, 14 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h
index 930b85b..eb9b2cf 100644
--- a/bin/ps/extern.h
+++ b/bin/ps/extern.h
@@ -51,7 +51,7 @@ char *elapsed(KINFO *, VARENT *);
char *elapseds(KINFO *, VARENT *);
char *emulname(KINFO *, VARENT *);
VARENT *find_varentry(VAR *);
-const char *fmt_argv(char **, char *, size_t);
+const char *fmt_argv(char **, char *, char *, size_t);
double getpcpu(const KINFO *);
char *kvar(KINFO *, VARENT *);
char *label(KINFO *, VARENT *);
diff --git a/bin/ps/fmt.c b/bin/ps/fmt.c
index 1e9fed8..4db6b8d 100644
--- a/bin/ps/fmt.c
+++ b/bin/ps/fmt.c
@@ -105,7 +105,7 @@ cmdpart(char *arg0)
}
const char *
-fmt_argv(char **argv, char *cmd, size_t maxlen)
+fmt_argv(char **argv, char *cmd, char *thread, size_t maxlen)
{
size_t len;
char *ap, *cp;
@@ -122,9 +122,14 @@ fmt_argv(char **argv, char *cmd, size_t maxlen)
cp = malloc(len);
if (cp == NULL)
errx(1, "malloc failed");
- if (ap == NULL)
- sprintf(cp, "[%.*s]", (int)maxlen, cmd);
- else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0)
+ if (ap == NULL) {
+ if (thread != NULL) {
+ asprintf(&ap, "%s/%s", cmd, thread);
+ sprintf(cp, "[%.*s]", (int)maxlen, ap);
+ free(ap);
+ } else
+ sprintf(cp, "[%.*s]", (int)maxlen, cmd);
+ } else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0)
sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd);
else
strcpy(cp, ap);
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index 21e8eaf..7f69137 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -29,7 +29,7 @@
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
-.Dd September 18, 2012
+.Dd February 7, 2013
.Dt PS 1
.Os
.Sh NAME
@@ -323,6 +323,7 @@ the include file
.It Dv "P_INMEM" Ta No "0x10000000" Ta "Loaded into memory"
.It Dv "P_SWAPPINGOUT" Ta No "0x20000000" Ta "Process is being swapped out"
.It Dv "P_SWAPPINGIN" Ta No "0x40000000" Ta "Process is being swapped in"
+.It Dv "P_PPTRACE" Ta No "0x80000000" Ta "Vforked child issued ptrace(PT_TRACEME)"
.El
.It Cm label
The MAC label of the process.
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index ebabc19..7099cc0 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -109,6 +109,7 @@ static int needcomm; /* -o "command" */
static int needenv; /* -e */
static int needuser; /* -o "user" */
static int optfatal; /* Fatal error parsing some list-option. */
+static int pid_max; /* kern.max_pid */
static enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT;
@@ -140,7 +141,7 @@ static void format_output(KINFO *);
static void *expand_list(struct listinfo *);
static const char *
fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int),
- KINFO *, char *, int);
+ KINFO *, char *, char *, int);
static void free_list(struct listinfo *);
static void init_list(struct listinfo *, addelem_rtn, int, const char *);
static char *kludge_oldps_options(const char *, char *, const char *);
@@ -148,6 +149,7 @@ static int pscomp(const void *, const void *);
static void saveuser(KINFO *);
static void scanvars(void);
static void sizevars(void);
+static void pidmax_init(void);
static void usage(void);
static char dfmt[] = "pid,tt,state,time,command";
@@ -200,6 +202,8 @@ main(int argc, char *argv[])
if (argc > 1)
argv[1] = kludge_oldps_options(PS_ARGS, argv[1], argv[2]);
+ pidmax_init();
+
all = descendancy = _fmt = nselectors = optfatal = 0;
prtheader = showthreads = wflag = xkeep_implied = 0;
xkeep = -1; /* Neither -x nor -X. */
@@ -722,7 +726,6 @@ addelem_gid(struct listinfo *inf, const char *elem)
return (1);
}
-#define BSD_PID_MAX 99999 /* Copy of PID_MAX from sys/proc.h. */
static int
addelem_pid(struct listinfo *inf, const char *elem)
{
@@ -740,7 +743,7 @@ addelem_pid(struct listinfo *inf, const char *elem)
if (*endp != '\0' || tempid < 0 || elem == endp) {
warnx("Invalid %s: %s", inf->lname, elem);
errno = ERANGE;
- } else if (errno != 0 || tempid > BSD_PID_MAX) {
+ } else if (errno != 0 || tempid > pid_max) {
warnx("%s too large: %s", inf->lname, elem);
errno = ERANGE;
}
@@ -753,7 +756,6 @@ addelem_pid(struct listinfo *inf, const char *elem)
inf->l.pids[(inf->count)++] = tempid;
return (1);
}
-#undef BSD_PID_MAX
/*-
* The user can specify a device via one of three formats:
@@ -1161,11 +1163,12 @@ sizevars(void)
static const char *
fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki,
- char *comm, int maxlen)
+ char *comm, char *thread, int maxlen)
{
const char *s;
- s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen);
+ s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm,
+ showthreads && ki->ki_p->ki_numthreads > 1 ? thread : NULL, maxlen);
return (s);
}
@@ -1193,7 +1196,7 @@ saveuser(KINFO *ki)
ki->ki_args = strdup("<defunct>");
else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL))
ki->ki_args = strdup(fmt(kvm_getargv, ki,
- ki->ki_p->ki_comm, MAXCOMLEN));
+ ki->ki_p->ki_comm, ki->ki_p->ki_tdname, MAXCOMLEN));
else
asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm);
if (ki->ki_args == NULL)
@@ -1204,7 +1207,7 @@ saveuser(KINFO *ki)
if (needenv) {
if (UREADOK(ki))
ki->ki_env = strdup(fmt(kvm_getenvv, ki,
- (char *)NULL, 0));
+ (char *)NULL, (char *)NULL, 0));
else
ki->ki_env = strdup("()");
if (ki->ki_env == NULL)
@@ -1352,6 +1355,18 @@ kludge_oldps_options(const char *optlist, char *origval, const char *nextarg)
}
static void
+pidmax_init(void)
+{
+ size_t intsize;
+
+ intsize = sizeof(pid_max);
+ if (sysctlbyname("kern.pid_max", &pid_max, &intsize, NULL, 0) < 0) {
+ warn("unable to read kern.pid_max");
+ pid_max = 99999;
+ }
+}
+
+static void
usage(void)
{
#define SINGLE_OPTS "[-aCcde" OPT_LAZY_f "HhjlmrSTuvwXxZ]"
OpenPOWER on IntegriCloud