Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F143144922
D43077.id131483.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D43077.id131483.diff
View Options
Index: bin/pkill/pkill.c
===================================================================
--- bin/pkill/pkill.c
+++ bin/pkill/pkill.c
@@ -66,8 +66,7 @@
#define STATUS_BADUSAGE 2
#define STATUS_ERROR 3
-#define MIN_PID 5
-#define MAX_PID 99999
+#define PID_MIN 5
/* Ignore system-processes (if '-S' flag is not specified) and myself. */
#define PSKIP(kp) ((kp)->ki_pid == mypid || \
@@ -828,6 +827,20 @@
usage();
}
+static int
+pidmax(void)
+{
+ int val;
+ size_t size;
+
+ size = sizeof(val);
+ if (sysctlbyname("kern.pid_max", &val, &size, NULL, 0) < 0) {
+ return (PID_MAX);
+ }
+
+ return (val);
+}
+
static int
takepid(const char *pidfile, int pidfilelock)
{
@@ -868,7 +881,7 @@
rval = strtol(line, &endp, 10);
if (*endp != '\0' && !isspace((unsigned char)*endp))
errx(STATUS_ERROR, "Invalid pid in file `%s'", pidfile);
- else if (rval < MIN_PID || rval > MAX_PID)
+ else if (rval < PID_MIN || rval > pidmax())
errx(STATUS_ERROR, "Invalid pid in file `%s'", pidfile);
return (rval);
}
Index: bin/ps/ps.c
===================================================================
--- bin/ps/ps.c
+++ bin/ps/ps.c
@@ -1469,7 +1469,7 @@
intsize = sizeof(pid_max);
if (sysctlbyname("kern.pid_max", &pid_max, &intsize, NULL, 0) < 0) {
xo_warn("unable to read kern.pid_max");
- pid_max = 99999;
+ pid_max = PID_MAX;
}
}
Index: sys/sys/proc.h
===================================================================
--- sys/sys/proc.h
+++ sys/sys/proc.h
@@ -910,6 +910,8 @@
#define P_MAGIC 0xbeefface
+#define PID_MAX 99999
+
#ifdef _KERNEL
/* Types and flags for mi_switch(9). */
@@ -954,8 +956,7 @@
* We use process IDs <= pid_max <= PID_MAX; PID_MAX + 1 must also fit
* in a pid_t, as it is used to represent "no process group".
*/
-#define PID_MAX 99999
-#define NO_PID 100000
+#define NO_PID (PID_MAX + 1)
#define THREAD0_TID NO_PID
extern pid_t pid_max;
Index: usr.bin/top/display.c
===================================================================
--- usr.bin/top/display.c
+++ usr.bin/top/display.c
@@ -245,7 +245,7 @@
/* mpid == -1 implies this system doesn't have an _mpid */
if (mpid != -1)
{
- printf("last pid: %5d; ", mpid);
+ printf("last pid: %*d; ", maxpidlen, mpid);
}
printf("load averages");
@@ -270,7 +270,7 @@
if (mpid != lmpid)
{
Move_to(x_lastpid, y_lastpid);
- printf("%5d", mpid);
+ printf("%*d", maxpidlen, mpid);
lmpid = mpid;
}
Index: usr.bin/top/machine.h
===================================================================
--- usr.bin/top/machine.h
+++ usr.bin/top/machine.h
@@ -88,6 +88,8 @@
void get_system_info(struct system_info *si);
int machine_init(struct statics *statics);
+extern int maxpidlen;
+
/* non-int routines typically used by the machine dependent module */
extern struct process_select ps;
Index: usr.bin/top/machine.c
===================================================================
--- usr.bin/top/machine.c
+++ usr.bin/top/machine.c
@@ -182,6 +182,9 @@
static int carc_enabled;
static int pageshift; /* log base 2 of the pagesize */
+static int maxcpulen;
+int maxpidlen;
+
/* define pagetok in terms of pageshift */
#define pagetok(size) ((size) << pageshift)
@@ -273,6 +276,22 @@
}
}
+static int
+numlen(const char *name)
+{
+ int len, val;
+
+ GETSYSCTL(name, val);
+
+ len = 0;
+ do {
+ val /= 10;
+ len++;
+ } while (val > 0);
+
+ return (len);
+}
+
int
machine_init(struct statics *statics)
{
@@ -307,6 +326,12 @@
GETSYSCTL("kern.ccpu", ccpu);
+ if (smpmode)
+ maxcpulen = numlen("hw.ncpu");
+ else
+ maxcpulen = 1;
+ maxpidlen = numlen("kern.pid_max");
+
/* this is used in calculating WCPU -- calculate it ahead of time */
logcpu = log(loaddouble(ccpu));
@@ -398,9 +423,11 @@
switch (displaymode) {
case DISP_CPU: {
- sbuf_printf(header, " %s", ps.thread_id ? " THR" : "PID");
+ sbuf_printf(header, "%*s",
+ ps.thread_id ? maxpidlen + 1 : maxpidlen,
+ ps.thread_id ? "THR" : "PID");
sbuf_printf(header, "%*s", ps.jail ? TOP_JID_LEN : 0,
- ps.jail ? " JID" : "");
+ ps.jail ? "JID" : "");
sbuf_printf(header, " %-*.*s ", namelength, namelength, uname_field);
if (!ps.thread) {
sbuf_cat(header, "THR ");
@@ -409,9 +436,9 @@
if (ps.swap) {
sbuf_printf(header, "%*s ", TOP_SWAP_LEN - 1, "SWAP");
}
- sbuf_cat(header, "STATE ");
+ sbuf_cat(header, "STATE ");
if (smpmode) {
- sbuf_cat(header, "C ");
+ sbuf_printf(header, "%*s ", maxcpulen, "C");
}
sbuf_cat(header, "TIME ");
sbuf_printf(header, " %6s ", ps.wcpu ? "WCPU" : "CPU");
@@ -420,9 +447,10 @@
break;
}
case DISP_IO: {
- sbuf_printf(header, " %s%*s %-*.*s",
- ps.thread_id ? " THR" : "PID",
- ps.jail ? TOP_JID_LEN : 0, ps.jail ? " JID" : "",
+ sbuf_printf(header, "%*s%*s %-*.*s",
+ ps.thread_id ? maxpidlen + 1 : maxpidlen,
+ ps.thread_id ? "THR" : "PID",
+ ps.jail ? TOP_JID_LEN : 0, ps.jail ? "JID" : "",
namelength, namelength, uname_field);
sbuf_cat(header, " VCSW IVCSW READ WRITE FAULT TOTAL PERCENT COMMAND");
sbuf_finish(header);
@@ -1080,6 +1108,13 @@
}
}
+ sbuf_printf(procbuf, "%*d ", (ps.thread_id) ? maxpidlen + 1 : maxpidlen,
+ (ps.thread_id) ? pp->ki_tid : pp->ki_pid);
+ if (ps.jail) {
+ sbuf_printf(procbuf, "%*d ", TOP_JID_LEN - 1, pp->ki_jid);
+ }
+ sbuf_printf(procbuf, "%-*.*s", namelength, namelength, (*get_userid)(pp->ki_ruid));
+
if (displaymode == DISP_IO) {
oldp = get_old_proc(pp);
if (oldp != NULL) {
@@ -1097,12 +1132,6 @@
p_tot = rup->ru_inblock + rup->ru_oublock + rup->ru_majflt;
s_tot = total_inblock + total_oublock + total_majflt;
- sbuf_printf(procbuf, "%5d ", (ps.thread_id) ? pp->ki_tid : pp->ki_pid);
-
- if (ps.jail) {
- sbuf_printf(procbuf, "%*d ", TOP_JID_LEN - 1, pp->ki_jid);
- }
- sbuf_printf(procbuf, "%-*.*s", namelength, namelength, (*get_userid)(pp->ki_ruid));
sbuf_printf(procbuf, "%6ld ", rup->ru_nvcsw);
sbuf_printf(procbuf, "%6ld ", rup->ru_nivcsw);
sbuf_printf(procbuf, "%6ld ", rup->ru_inblock);
@@ -1112,16 +1141,10 @@
sbuf_printf(procbuf, "%6.2f%% ", s_tot == 0 ? 0.0 : (p_tot * 100.0 / s_tot));
} else {
- sbuf_printf(procbuf, "%5d ", (ps.thread_id) ? pp->ki_tid : pp->ki_pid);
- if (ps.jail) {
- sbuf_printf(procbuf, "%*d ", TOP_JID_LEN - 1, pp->ki_jid);
- }
- sbuf_printf(procbuf, "%-*.*s ", namelength, namelength, (*get_userid)(pp->ki_ruid));
-
if (!ps.thread) {
- sbuf_printf(procbuf, "%4d ", pp->ki_numthreads);
+ sbuf_printf(procbuf, " %4d ", pp->ki_numthreads);
} else {
- sbuf_printf(procbuf, " ");
+ sbuf_printf(procbuf, " ");
}
sbuf_printf(procbuf, "%3d ", pp->ki_pri.pri_level - PZERO);
@@ -1141,7 +1164,7 @@
} else {
cpu = pp->ki_lastcpu;
}
- sbuf_printf(procbuf, "%3d ", cpu);
+ sbuf_printf(procbuf, "%*d ", maxcpulen, cpu);
}
sbuf_printf(procbuf, "%6s ", format_time(cputime));
sbuf_printf(procbuf, "%6.2f%% ", ps.wcpu ? 100.0 * weighted_cpu(PCTCPU(pp), pp) : 100.0 * PCTCPU(pp));
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 27, 1:28 PM (13 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28056394
Default Alt Text
D43077.id131483.diff (6 KB)
Attached To
Mode
D43077: Don't hardcode maximum PID.
Attached
Detach File
Event Timeline
Log In to Comment