summaryrefslogtreecommitdiffstats
path: root/bin/ps
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2012-12-12 15:45:03 +0000
committerpjd <pjd@FreeBSD.org>2012-12-12 15:45:03 +0000
commitc03248a464173c43816755d3e8ce21b0686748a4 (patch)
treea8e4daf4494e911a1c7852ce5c4a7b701eab01e9 /bin/ps
parentdddecfb2fbb9da35ba472f32182b6707381d55c7 (diff)
downloadFreeBSD-src-c03248a464173c43816755d3e8ce21b0686748a4.zip
FreeBSD-src-c03248a464173c43816755d3e8ce21b0686748a4.tar.gz
Use kern.max_pid sysctl to obtain maximum PID number instead of using local
define. Reviewed by: jhb
Diffstat (limited to 'bin/ps')
-rw-r--r--bin/ps/ps.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index ebabc19..e9fc5fa 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;
@@ -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:
@@ -1352,6 +1354,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